Date: Wed, 22 May 2024 13:25:27 +0200
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
>
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
Received on 2024-05-22 11:25:41