我需要将可变数量的字符串文字连接成一个以在 static_assert() 中使用它
我尝试使用带有结构的模板,但编译器不喜欢将文字作为模板参数。
error: the address of ‘m1’ is not a valid template argument because it does not have static storage duration.
error: ‘"thre"’ is not a valid template argument for type ‘const char*’ because string literals can never be used in this context
我也尝试过完美转发,但出现错误:‘args#0’ is not a constant expression
template<size_t size>
constexpr size_t const_strssize(const char (&)[size]) {
return size;
}
template<class... Ts>
constexpr size_t const_strssize(Ts&&... args) {
return const_sum<(const_strssize(std::forward<const Ts>(args)), ...)>::get;
}
澄清一下,我不能这样做,"string1" "string2"
因为我从函数中得到的一些字符串返回了。
请不要建议 strlen 或 memcpy 之类的东西。我知道,它们可以在编译时计算出来。