【发布时间】:2017-01-05 02:09:44
【问题描述】:
我正在探索我可以从这个答案中获得 constexpr char const* 连接多远: constexpr to concatenate two or more char strings
我有以下用户代码,可以准确显示我正在尝试做的事情。似乎编译器看不到函数参数(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();
}
}
【问题讨论】:
标签: c++ c++11 compile-time-constant