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();
}
}