1

My code is as follow:

template  <typename T>
void func(T&& param){
    using boost::typeindex::type_id_with_cvr;
    cout << "T = " << type_id_with_cvr<T>().pretty_name() << " , "
        << "param = " << type_id_with_cvr<decltype(param)>().pretty_name() << '\n';
}
int main(void){
    const char name[] = "J. P. Briggs";
    func(name);
    func("Hello World");
    func(24);
    return 0;
}

its result:

T = char const (&) [13] , param = char const (&) [13]
T = char const (&) [13] , param = char const (&) [13]
T = int , param = int&&

Isn't the literal "Hello World" a rvalue? If so, why the result of the statement func("Hello World"); is T = char const (&) [13] , param = char const (&) [13] rather than T = char const[13] , param = char const(&&) [13]??
Is there something wrong ?

cigien
  • 57,834
  • 11
  • 73
  • 112
Phoenix Chao
  • 390
  • 3
  • 19
  • Does this answer your question? [Why are string literals l-value while all other literals are r-value?](https://stackoverflow.com/questions/10004511/why-are-string-literals-l-value-while-all-other-literals-are-r-value) – cigien Sep 15 '20 at 12:56
  • Yes, it does. Thanks a lot – Phoenix Chao Sep 16 '20 at 00:33

0 Answers0