C++ Compile-Time string manipulation

前端 未结 2 1022
独厮守ぢ
独厮守ぢ 2020-12-31 23:50

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

相关标签:
2条回答
  • 2021-01-01 00:16

    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.

    0 讨论(0)
  • 2021-01-01 00:19

    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
    0 讨论(0)
提交回复
热议问题