【发布时间】:2016-05-07 23:41:59
【问题描述】:
目前,只有双精度可以在用户定义的文字中生成字符模板:
template <char...> double operator "" _x();
// Later
1.3_x; // OK
"1.3"_y; // C++14 does not allow a _y user-
// defined operator to parse that as a template of chars
有没有一种聪明的方法可以使用用户定义的文字生成std::integer_sequence 的字符。换句话说,_y(const char*, std::size_t) 的代码是什么,所以我最终得到了 std::integer_sequence<char, '1', '.', '3'>?
【问题讨论】:
-
N3599 可能会进入 C++1Z。
-
你真的需要
integer_sequence吗?这闻起来像是 XY 问题。 -
@Columbo 你从哪里得到这些信息的?上次我听说它在 EWG 中被拒绝,支持
string_literal<N>。 -
@T.C.直from the author.
-
如果你不想使用编译器扩展,我知道的最接近的就是这样使用:
constexpr const char literal[] = "delta"; using X = make_char_sequence<sizeof(literal), literal>;。如果您对细节感兴趣,请告诉我。
标签: c++ templates c++14 template-meta-programming user-defined-literals