5
我正在探索多远我可以采取constexpr字符常量*从这个答案串联: constexpr to concatenate two or more char stringsconstexpr C字符串拼接,在constexpr上下文中使用参数
我有以下的用户代码,准确显示我米试图做。看起来,编译器看不到函数参数(a和b)以constexpr的形式传入。
任何人都可以看到一种方法,使两个我表明不工作,实际工作?能够通过像这样的功能组合字符数组将是非常方便的。
template<typename A, typename B>
constexpr auto
test1(A a, B b)
{
return concat(a, b);
}
constexpr auto
test2(char const* a, char const* b)
{
return concat(a, b);
}
int main()
{
{
// works
auto constexpr text = concat("hi", " ", "there!");
std::cout << text.data();
}
{
// doesn't work
auto constexpr text = test1("uh", " oh");
std::cout << text.data();
}
{
// doesn't work
auto constexpr text = test2("uh", " oh");
std::cout << text.data();
}
}