C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Template parameter packs followed by more types

From: Jarrad Waterloo <descender76_at_[hidden]>
Date: Wed, 22 May 2024 08:02:45 -0400
+1

I have a similar need for wanting to add default initialized arguments at
the end of my variadic templates such as source_location.


On Wed, May 22, 2024 at 7:25 AM Rhidian De Wit via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> How would the compiler, and the user, figure out where the parameter pack
> ends, and the next template parameter pack starts?
>
> I suppose you could work out that the template parameter pack is only the
> first argument in your example, but it feels very complicated to figure
> this out.
> This being said, it would be nice if this *were* possible, since it can
> be useful to have template parameters after template parameter packs (I've
> personally run into this issue, but I've been able to solve it with
> workarounds).
>
> One potential problem I see is something like this:
>
> template<typename ... Ts, typename U>void Foo(){ std::cout << sizeof ... (Ts) << ", " << sizeof(U) << "\n"; // dummy code}int main(){ Foo<int>();}
>
> How does the compiler figure this one out? *Ts* can be empty, but it could also match the supplied *int*.
> You could match the parameter pack to be empty and *U* to be the int, but this seems like a complicated problem, that I'm sure can be made far more complex than what I can come up with on the fly.
>
>
> Sincerely,
>
> Op wo 22 mei 2024 om 13:10 schreef Frederick Virchanza Gotham via
> Std-Proposals <std-proposals_at_[hidden]>:
>
>> The following program fails to compile in C++23:
>>
>> template<typename... A, typename B>
>> void Func(A&&... a, B &&b)
>> {
>>
>> }
>>
>> int main(void)
>> {
>> Func(1, 5.2);
>> }
>>
>> Forgetting about how computer programming languages and compilers work
>> for a minute -- if we just try to apply simple reasoning here, it
>> would make sense that Func would be instantiated as follows:
>> A = int
>> B = double
>>
>> It would make sense for the above program to be equivalent to:
>>
>> void Func(int &&a, double &&b)
>> {
>>
>> }
>>
>> int main(void)
>> {
>> Func(1, 5.2);
>> }
>>
>> Is there any reason why C++26 cannot be amended to allow this?
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>
>
> --
> Rhidian De Wit
> Software Engineer - Barco
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-05-22 12:02:57