Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Template Quine

It is known that C++ templates are turing complete. As such it should be possible to output a quine that is essentially rendered at compile time. Does anyone know if such a quine has been written yet or where I could find one.

like image 816
Jeff Avatar asked Feb 27 '23 14:02

Jeff


1 Answers

Templates can perform any kind of computation on integer data elements, true. But they aren't so good at I/O.

What form should the answer take? A template that generates a function that, when executed, outputs the quine source? That's not really compile time. A template that generates a compile-time list of characters (hundreds or thousands of classes long) composing quine source? Maybe that's better, but you still need to run the program to output it.

Also, templates are very verbose, and although they are turing complete, that is only within a small memory constraint guaranteed recommended by the standard. You can only expect so much recursion, for example, beyond which the program is highly compiler-specific. It might be impossible to write a "meaningfully computed" quine which stores itself in a portable form.

like image 54
Potatoswatter Avatar answered Mar 12 '23 22:03

Potatoswatter