Viatorus / compile-time-printer

Prints values and types during compilation!
Boost Software License 1.0
55 stars 0 forks source link

Add documentation (if possible) on how to integrate CTP C++ code into reStructuredText documents compiled by Sphinx #24

Open anadon opened 1 year ago

anadon commented 1 year ago

I think I briefly saw somewhere use of this project as a way to include limited C++ snippets that are "run" at text generation time without the need for some meta-level build system nonsense. How does one do this?

I also can't get the following to work: compile-time-printer -- g++ -std=c++20 -I ../include/ -fsyntax-only -fpermissive examples/compile_time_examples.cpp for https://gitlab.com/anadon/prime_generator_header/-/blob/master/examples/compile_time_examples.cpp

Viatorus commented 1 year ago

Hi @anadon,

I am not aware of it. I cannot really help you with that. You have to somehow compile your code-snippet and integrate the output later inside the documention.

To your second question: You must evaluate your code at compile-time via constexpr/consteval.

Doing this is also bad-practice: Now ctp::printf and the C function printf are in the same scope.

using namespace std;
using ctp::printf;
using madlib::primes;
using madlib::prime_generator;
anadon commented 1 year ago

I think I could work on it if the installation steps worked as described, where after installed via pip the header becomes available when run as below. As for the using statements above, it is for clarity to new users; the choice of using order is intentional to replace the standard printf().

anadon@Poymon:~/Documents/code/prime_generator_header$ compile-time-printer --  g++ -std=c++20 -I include/ -fsyntax-only examples/compile_time_examples.cpp
No CTP output found.
examples/compile_time_examples.cpp:4:10: fatal error: ctp/ctp.hpp: No such file or directory
    4 | #include <ctp/ctp.hpp>
      |          ^~~~~~~~~~~~~
compilation terminated.