Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Compile-Time string manipulation

I looked at boost's mpl::string, but there doesn't seem to be an easy way of converting string literals to the single-quotation-integer-based format of mpl::string. What I am trying to do is to generate at compile time an XML realization of some simple data structures using compile time strings. I am striving for having macros generate the structures themselves and insert a constant "meta" field inside them, containing said XML string.

like image 593
user394460 Avatar asked Sep 15 '10 13:09

user394460


1 Answers

The short answer is no, there is no easy way. At least not using C++ alone, and at compile time. You can use scripts or some other code generator to produce mpl::strings with the correct literals. C++0x will bring user defined literals [1], that allow an easy manipulation of literals, character by character, for example, using variadic templates.

  1. http://en.wikipedia.org/wiki/C%2B%2B0x#User-defined_literals
like image 200
Diego Sevilla Avatar answered Nov 19 '22 05:11

Diego Sevilla