C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Default arguments should participate in template argument deduction

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Tue, 29 Mar 2022 19:55:50 +0200
wt., 29 mar 2022 o 18:42 Edward Catmur via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
> On Tue, 29 Mar 2022 at 16:38, Tom Honermann via Std-Proposals <std-proposals_at_[hidden]> wrote:
>>
>> On 3/29/22 6:55 AM, Timur Doumler via Std-Proposals wrote:
>>
>> I don’t agree that the second example is bizarre. In fact, I had this exact case in a real-world codebase not too long ago. The idea was that you start an audio device and pass it a process callback (which is mandatory) as well as “device started” and device stopped” callbacks, which are optional callbacks that the device will call before it starts processing and after it stopped processing so you can allocate/deallocate resources required for processing. It would be very nice to be able to write
>>
>> 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 / 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`.
>
> It also isn't a solution if the callback needs to accept more than one set of arguments, or an argument type which isn't easily calculated within the signature.

Would it be fixed by Proxy proposal?
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0957r6.pdf
Still we need to pay some for type erasure overhead but calling set is
fully customizabe.

> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-03-29 17:56:03