How useful would Inheriting Constructors be in C++?

2) Are there any technical reasons you can think of that would preclude “perfect forwarding constructors” from being an adequate alternative? I have shown one problem with that perfect forwarding approach here: Forwarding all constructors in C++0x . Also, the perfect forwarding approach can’t “forward” the expliciteness of base-class constructors: Either it is always a … Read more

Why use a perfectly forwarded value (a functor)?

In Brief… The TL;DR, you want to preserve the value category (r-value/l-value nature) of the functor because this can affect the overload resolution, in particular the ref-qualified members. Function definition reduction To focus on the issue of the function being forwarded, I’ve reduced the sample (and made it compile with a C++11 compiler) to; template<class … 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

Forwarding of return values. Is std::forward is needed?

In the case that you do know that t will not be in a moved-from state after the call to f, your two somewhat sensible options are: return std::forward<T>(t) with type T&&, which avoids any construction but allows for writing e.g. auto&& ref = wrapper(42);, which leaves ref a dangling reference return std::forward<T>(t) with type … Read more

Should all/most setter functions in C++11 be written as function templates accepting universal references?

You know the classes A and B, so you know if they are movable or not and if this design is ultimately necessary. For something like std::string, it’s a waste of time changing the existing code unless you know you have a performance problem here. If you’re dealing with auto_ptr, then it’s time to rip … Read more

Can I typically/always use std::forward instead of std::move?

The two are very different and complementary tools. std::move deduces the argument and unconditionally creates an rvalue expression. This makes sense to apply to an actual object or variable. std::forward takes a mandatory template argument (you must specify this!) and magically creates an lvalue or an rvalue expression depending on what the type was (by … Read more

Perfect forwarding – what’s it all about? [duplicate]

http://www.justsoftwaresolutions.co.uk/cplusplus/rvalue_references_and_perfect_forwarding.html Why is this useful? Well, it means that a function template can pass its arguments through to another function whilst retaining the lvalue/rvalue nature of the function arguments by using std::forward. This is called “perfect forwarding”, avoids excessive copying, and avoids the template author having to write multiple overloads for lvalue and rvalue references.

Is there a difference between universal references and forwarding references?

Do they mean the same thing? Universal reference was a term Scott Meyers coined to describe the concept of taking an rvalue reference to a cv-unqualified template parameter, which can then be deduced as either a value or an lvalue reference. At the time the C++ standard didn’t have a special term for this, which … Read more