C ++ Template Quine

C ++ templates are known to be complete. Thus, it should be possible to output quine, which is essentially displayed at compile time. Does anyone know if there was still such a queen, or where I could find him.

+4
source share
2 answers

Templates can do any computation on integer data elements, true. But they are not so good at I / O.

What form should the answer take? A template that generates a function that, when executed, outputs a quine source? This is not exactly compilation time. A template that generates a list of compile-time characters (hundreds or thousands of classes) that make up a quine source? This may be better, but you still need to run the program to output it.

In addition, the templates are very verbose, and although they are fully completed, that is, only within the limited memory limit recommended by the standard. For example, you can expect so much recursion for which the program is highly dependent on the compiler. It may not be possible to write a “meaningfully calculated” quine, which is stored in a portable form.

+5
source

Templates have only one form of direct output - error / warning messages. Since there is no guarantee about the form they take, you cannot write anything that should definitely be quine, and everything you write will almost certainly have other text interspersed with the source code.

With a compiler that injects the source into the error message, getting each line output is too easy - just make sure every statement contains an error.

+3
source

Source: https://habr.com/ru/post/1301370/


All Articles