C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Extreme Template Parameter Possibilities

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Wed, 30 Nov 2022 07:47:22 +0100
Hi Frederick, would you be able to copy-paste really arbitrary text? E.g. could you, with the text,  - refer to other templates with arbitrary text (recursive)?  - define things including new templates with arbitrary text?  - leave the function scope by copy-pasting closing braces?   Currently C++ quite clearly separates strings and identifiers. Small, specific exceptions:  - preprocessor: C Macro stringify #MACRO  - logging and debugging facilities: typeid().name(), <stacktrace>   This has advantages:  - possibility by the programmers (library + user code) to write more general code  - templates types act like any type (the same for template functions, template classes, template variables)  - aliasing, mangling  - sorting with qualified id, namespaces, modules   Breaking this distinction has to be done very very carefully. One has to consider build time, size of the executables, toolability of the new source code, consistency of the language, quality of code that would be written, new best practices, ...   The proposal goes very far into reflection and metaclasses territory. The current direction seems to be not to allow string-like modification of the program, but to work on the AST (Abstract Syntax Tree) level.   You should think about, whether you want to do general string replacement. Then an improved textual preprocessor, which runs in an early pass of compilation, could be a better direction, or you want something integrated into the compilation interacting with constexpr, possibly stored in modules, etc., then you should find out, where sensible limits are. A feature to allow everything, does not necessarily bring the language forward. Neither for compiler implementers nor for programmers. Programming lives from limitations, e.g. private, const, class boundaries, contracts, ...   Best, Sebastian   -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Mo 28.11.2022 17:27 Betreff:[std-proposals] Extreme Template Parameter Possibilities An:std-proposals <std-proposals_at_[hidden]>; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; 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);        } -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-11-30 06:47:24