相关疑难解决方法(0)

c ++:从模板参数生成字符串文字

template < unsigned int i >
struct t {
  static const char *s;
};
template < unsigned int i >
const char* t<i>::s = ...;
Run Code Online (Sandbox Code Playgroud)

其中 ...是"0 1 2 ... i-1",例如"0 1 2 3 4" i == 5.

这可能吗?(请不要在运行时做这个解决方案!)

  • 问题是出于好奇(用预处理器宏/常量做这件事很容易,但模板参数怎么样)?
  • 含义是:编译时生成的字符串文字.我现在看到const它不会强制执行此操作,但可以对字符串生成采用任何运行时评估函数.

c++ templates metaprogramming string-literals

6
推荐指数
2
解决办法
3169
查看次数

标签 统计

c++ ×1

metaprogramming ×1

string-literals ×1

templates ×1