should std::common_type use std::decay?

should std::common_type use std::decay? Yes, see Library Working Group Defect #2141. Short version (long version, see link above): declval<A>() returns a A&& common_type is specified via declval, n3337: template <class T, class U> struct common_type<T, U> { typedef decltype(true ? declval<T>() : declval<U>()) type; }; common_type<int, int>::type therefore yields int&&, which is unexpected proposed resolution … Read more

Why is taking the address of a temporary illegal?

&std::string(“Hello World”) The problem with this isn’t that std::string(“Hello World”) yields a temporary object. The problem is that the expression std::string(“Hello World”) is an rvalue expression that refers to a temporary object. You cannot take the address of an rvalue because not all rvalues have addresses (and not all rvalues are objects). Consider the following: … Read more

Is it valid to bind non-const lvalue-references to rvalues in C++ 11?(modified)

should that work in c++11? No, it should not. Foo is a custom class, I don’t understand why the first two line compiles It compiles only with MSVC. MSVC has an (arguably useful) compiler extension that allows binding lvalues of user-defined types to rvalues, but the Standard itself forbids this. See, for instance, this live … Read more

what is return type of assignment operator?

The standard correctly defines the return type of an assignment operator. Actually, the assignment operation itself doesn’t depend on the return value – that’s why the return type isn’t straightforward to understanding. The return type is important for chaining operations. Consider the following construction: a = b = c;. This should be equal to a … Read more