C ++编译时字符串操作 [英] C++ Compile-Time string manipulation

查看:126
本文介绍了C ++编译时字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了boost的mpl :: string,但是似乎没有一种简单的方法将字符串字面量转换为基于单引号整数的mpl :: string格式。我想做的是在编译时生成使用编译时字符串的一些简单的数据结构的XML实现。我正在努力让宏生成结构本身,并在其中插入一个包含所述XML字符串的常量meta字段。

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.

推荐答案

简短的答案是没有,没有容易的方法。至少不是单独使用C ++,而是在编译时。您可以使用脚本或其他代码生成器以正确的文字生成 mpl :: string 。 C ++ 0x将带来用户定义的文字[1],允许简单的字符操作,例如,使用可变参数模板。

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

  1. http://en.wikipedia.org/wiki/C%2B%2B0x#User-defined_literals

这篇关于C ++编译时字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆