C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Extreme Template Parameter Possibilities

From: Gergely Nagy <gergely.nagy.alt_at_[hidden]>
Date: Mon, 28 Nov 2022 17:54:58 +0100
I think this would cause more harm than good.

Can you explain what is the problem you want to slove that cannot be done
any other way?

On Mon, Nov 28, 2022, 17:52 Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Mon, Nov 28, 2022 at 4:27 PM Frederick Virchanza Gotham
> <cauldwell.thomas_at_[hidden]> wrote:
>
> > template<text special_cleanup>
> > int CloseHandle(int const arg)
> > {
> > StopComms(arg);
> > SetInactive(arg);
> >
> > {<special_cleanup>};
> >
> > CloseFile(arg);
> > }
>
>
> Of course with the above example, we could have just passed an
> "std::function<void(void)>" as a normal function parameter, but if we
> could copy-paste arbitrary text into a template function then we could
> do the following:
>
> CloseHandle<"if constexpr(std::is_class_v<SomeType>) return;">();
>
> We could return prematurely from a function, or we could change a
> stack variable into a static-duration variable:
>
> template <text T>
> int Func(int arg)
> {
> {<T>} int count = 0;
>
> return ++count + arg;
> }
>
> And then invoke it like this:
>
> Func<"static">(5);
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-11-28 16:55:10