C++ Logo

std-proposals

Advanced search

[std-proposals] Extreme Template Parameter Possibilities

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 28 Nov 2022 16:27:37 +0000
What if we could use template parameters to copy-paste arbitrary text
into the body of a function?

For example let's say we had:

        template<text T>
        int Func(int const arg)
        {
                return arg {<T>} 7;
        }

Then we could use it as follows:

        int main(void)
        {
                return Func<"+">(-7);
        }

This would allow us to do all sorts of things, even:

        template<text special_cleanup>
        int CloseHandle(int const arg)
        {
                StopComms(arg);
                SetInactive(arg);

                {<special_cleanup>};

                CloseFile(arg);
        }

        int main(void)
        {
                int handle = OpenHandle("readme.txt");

                CloseHandle<"UnlockMutex(g_mtx_resources)">(handle);
        }

Received on 2022-11-28 16:27:49