Is it possible to read a file at compile time?

前端 未结 3 1392
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 13:21

I am wondering if it is possible in C++11/14 to actually read files at compile time. For example the following code will only compile if it can successfully read the file.

3条回答
  •  忘掉有多难
    2020-12-03 13:48

    #define STR(x) #x
    
    const char* a =
    { 
    #include "foo.glsl" 
    };
    

    and foo.glsl should enclose its content in STR( ... )

    upd. This will properly handle commas

    #define STRINGIFY(...) #__VA_ARGS__
    #define STR(...) STRINGIFY(__VA_ARGS__)
    

提交回复
热议问题