Date: Sat, 4 Apr 2026 19:00:47 +0200
sob., 4 kwi 2026 o 17:36 Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> napisaĆ(a):
>
> On Saturday, 4 April 2026 03:04:27 Pacific Daylight Time Marcin Jaczewski via
> Std-Proposals wrote:
> > Like:
> > ```
> > void foo(int i)
> > {
> > switch(i) { ... }
> > }
> > void bar(int i)
> > {
> > for (auto& x: data) for(i);
> > }
> > ```
> >
> > change into:
> >
> > ```
> > template<int i>
> > void foo()
> > {
> > //code based on i, like `std::get<i>`
> > }
> > void bar(int i)
> > {
> > switch (i){
> > case 0:
> > for (auto& x: data)
> > {
> > foo<0>();
> > }
> > break;
> > case 1:
> > for (auto& x: data)
> > {
> > foo<1>();
> > }
> > break;
> > //etc.
> > }
> > }
> > ```
>
> Compilers already do that on their own.
>
> They may not be doing that all the time, though. So if you do need to enforce
> this, implementing manually may be necessary.
>
> Do we need a new language construct for this? Especially in the presence of
> template for?
>
Yes, a compiler can do this but needs to have every function inlined,
I was thinking in a more general case
when a programmer creates code that is in different TU or code is too
complex for the compiler to digest.
And the only thing I would propose is that `template for` can create
`case` but this side tangent to this whole thread.
My post was an overall search for a more proper solution to Muneem's
problem that uses currently available tools or needs only small tweaks
to langage.
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel Data Center - Platform & Sys. Eng.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
<std-proposals_at_[hidden]> napisaĆ(a):
>
> On Saturday, 4 April 2026 03:04:27 Pacific Daylight Time Marcin Jaczewski via
> Std-Proposals wrote:
> > Like:
> > ```
> > void foo(int i)
> > {
> > switch(i) { ... }
> > }
> > void bar(int i)
> > {
> > for (auto& x: data) for(i);
> > }
> > ```
> >
> > change into:
> >
> > ```
> > template<int i>
> > void foo()
> > {
> > //code based on i, like `std::get<i>`
> > }
> > void bar(int i)
> > {
> > switch (i){
> > case 0:
> > for (auto& x: data)
> > {
> > foo<0>();
> > }
> > break;
> > case 1:
> > for (auto& x: data)
> > {
> > foo<1>();
> > }
> > break;
> > //etc.
> > }
> > }
> > ```
>
> Compilers already do that on their own.
>
> They may not be doing that all the time, though. So if you do need to enforce
> this, implementing manually may be necessary.
>
> Do we need a new language construct for this? Especially in the presence of
> template for?
>
Yes, a compiler can do this but needs to have every function inlined,
I was thinking in a more general case
when a programmer creates code that is in different TU or code is too
complex for the compiler to digest.
And the only thing I would propose is that `template for` can create
`case` but this side tangent to this whole thread.
My post was an overall search for a more proper solution to Muneem's
problem that uses currently available tools or needs only small tweaks
to langage.
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel Data Center - Platform & Sys. Eng.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2026-04-04 17:01:02
