6

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.

user394460
  • 193
  • 10

2 Answers2

3

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
Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87
  • 1
    Is there any guarantee that user defined literals are processed at compile time? I always assumed we are at the mercy of the optimizer for that. – peterchen Jan 07 '11 at 10:44
  • The question is that they are at least passed to the program in an easy writable and maintainable manner, that is, you don't have to write `'a','b','c',...`. – Diego Sevilla Jan 10 '11 at 17:13
0

Here is an article regarding the subject: http://akrzemi1.wordpress.com/2011/05/11/parsing-strings-at-compile-time-part-i/. The author implements a simple RPN arithmetic calculator that works during compile-time using user string literals and constexpr. I won't attempt to provide any more summary of the article here.

void-pointer
  • 14,247
  • 11
  • 43
  • 61