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它不会强制执行此操作,但可以对字符串生成采用任何运行时评估函数.