Date: Wed, 30 Mar 2022 02:39:33 +0100
On Tue, 29 Mar 2022 at 19:37, Zhihao Yuan <zy_at_[hidden]> wrote:
> On Tuesday, March 29th, 2022 at 9:42 AM, Edward Catmur via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
> On Tue, 29 Mar 2022 at 16:38, Tom Honermann via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>>
>> void start_device(auto process_callback, auto started_callback = []{},
>> auto stopped_callback = []{});
>>
>> Do you really want templates in that case? It seems to me that
>> std::function_ref as proposed in P0792 <https://wg21.link/p0792> / P2472
>> <https://wg21.link/p2472> provides a better solution here.
>>
> std::function_ref is a great solution in many cases, but it does mean
> paying the overhead of type erasure, so you may prefer to keep it a
> template and use `std::invocable<> auto`.
>
>
> Are you sure about that: https://godbolt.org/z/PMT3GG56G
>
Oh, nice. Still, relying on the optimizer virtualizing and inlining isn't
always the best idea, and some optimizations (like constant folding, IIRC)
don't make it across the function call boundary.
> On Tuesday, March 29th, 2022 at 9:42 AM, Edward Catmur via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
> On Tue, 29 Mar 2022 at 16:38, Tom Honermann via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>>
>> void start_device(auto process_callback, auto started_callback = []{},
>> auto stopped_callback = []{});
>>
>> Do you really want templates in that case? It seems to me that
>> std::function_ref as proposed in P0792 <https://wg21.link/p0792> / P2472
>> <https://wg21.link/p2472> provides a better solution here.
>>
> std::function_ref is a great solution in many cases, but it does mean
> paying the overhead of type erasure, so you may prefer to keep it a
> template and use `std::invocable<> auto`.
>
>
> Are you sure about that: https://godbolt.org/z/PMT3GG56G
>
Oh, nice. Still, relying on the optimizer virtualizing and inlining isn't
always the best idea, and some optimizations (like constant folding, IIRC)
don't make it across the function call boundary.
Received on 2022-03-30 01:39:44