c++ - constexpr c string concatenation, parameters used in a constexpr context -


i exploring how far take constexpr char const* concatenation answer: constexpr concatenate 2 or more char strings

i have following user code shows i'm trying do. seems compiler can't see function parameters (a , b) being passed in constexpr.

can see way make 2 indicate don't work below, work? extremely convenient able combine character arrays through functions this.

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

live example

concat need const char (&)[n], , in both of case, type const char*, might change function as:

template<typename a, typename b> constexpr auto test1(const a& a, const b& b) {   return concat(a, b); } 

demo


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -