Questions tagged [universal-reference]

A universal reference refers to a reference type that may either be an lvalue reference or an rvalue reference depending on its initializer. They allow the user to employ perfect-forwarding.

Both auto&& and the T&& in template<class T> void f(T&&); are universal references.

Scott Meyers did an excellent talk on the topic, which can be found here.

When adding this to the draft of the next C++ standard, the focus was on the perfect-forwarding, and so the term forwarding reference was chosen.

63 questions
0
votes
1 answer

Universal reference in a member function pointer

I am having some troubles understanding why the following code cannot compile #include #include #define PRINT_FUNC() {std::cout << __PRETTY_FUNCTION__ << std::endl;} struct Obj { Obj(){PRINT_FUNC();} int run (float f,…
0
votes
1 answer

Using template argument from universal reference as const ref

My actual usecase takes a few more arguments but it simplifies to this: template< typename Arg1 > bool algorithm( Arg1&& p1, **p2 here** ); With just that its evident that Arg1 will collapse in some way and likely become some kind of reference. p1…
qeadz
  • 1,476
  • 1
  • 9
  • 17
0
votes
2 answers

How to use universal references without other type deduction

I'm writing a wrapper class for a class of type inner_t. Can I call the proper constructor (lvalue reference or rvalue reference) for the inner class in the following way? template struct u_ref { }; template
1 2 3 4
5