Why do forwarding references have the same syntax as rvalue references?

I think it happened the other way around. The initial idea was to introduce rvalue-references into the language, meaning that “the code providing the double-ampersand reference does not care about what will happen to the referred-to object”. This permits move semantics. This is nice. Now. The standard forbids constructing a reference to a reference, but … Read more

Is there a reason declval returns add_rvalue_reference instead of add_lvalue_reference

With add_rvalue_reference: declval<Foo>() is of type Foo&&. declval<Foo&>() is of type Foo& (reference collapsing: “Foo& &&” collapses to Foo&). declval<Foo&&>() is of type Foo&& (reference collapsing: “Foo&& &&” collapses to Foo&&). With add_lvalue_reference: declval<Foo>() would be of type Foo&. declval<Foo&>() would be of type Foo& (reference collapsing: “Foo& &” collapses to Foo&). declval<Foo&&>() would be … Read more

What are the reference collapsing rules, and how are they utilized by the C++ standard library?

The reference collapsing rules (save for A& & -> A&, which is C++98/03) exist for one reason: to allow perfect forwarding to work. “Perfect” forwarding means to effectively forward parameters as if the user had called the function directly (minus elision, which is broken by forwarding). There are three kinds of values the user could … Read more

How does std::forward work, especially when passing lvalue/rvalue references? [duplicate]

I think the explanation of std::forward as static_cast<T&&> is confusing. Our intuition for a cast is that it converts a type to some other type — in this case it would be a conversion to an rvalue reference. It’s not! So we are explaining one mysterious thing using another mysterious thing. This particular cast is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)