Disclaimer: this is going to be lame.
Two questions:
The part driven by curiosity: what is the exact type of a quote-marked string? Prevoiusly I thought that it's a C
char[]
string converted tostd::string
when it is needed, but sometype_traits
experiments revealed this:std::is_lvalue_reference<decltype ("string")>::value; -> true std::is_object<std::remove_reference<decltype ("string")>>::value; -> true std::is_same<decltype ("string"), std::string&>::value; -> false
The lame part: what type of argument should a function take to be able to deal with calls like
fun("str")
? The reason for this question is that the following example does not compile because of thestatic_assert
:template <typename T> void fun (const T &what) { static_assert(sizeof(T) < 0, "Something unsupported"); } void fun (std::string str) { std::cout << "Copied" << std::endl; } void fun (const std::string &str) { std::cout << "Lvalue" << std::endl; } void fun (std::string &&str) { std::cout << "Rvalue" << std::endl; } int main () { fun ("str"); //static assertion failed return 0; }
More over, commenting the template out causes
error: call of overloaded 'fun(const char [4])' is ambiguous candidates are: [all three options]
It does not seem ambiguous to me. Why does not it construct a temporary string and pass it by rvalue-reference?