Have anybody seen Scot Meyers' video on Universal references? In order for a reference to be "universal" two requirements should be fulfilled :
1)variable should have double ampersand after it's type : sometype&&
2) the type should be deduced .

The second point is somewhat confusing to me: despite examples provided there, Meyers hasn't given a clear definition :
what does mean deduced type?

So the question is : could you give if not a clear difinition of what criteria a type should fulfill in order to be called "deduced", but at least your vision on it.

Thanks beforehand.

Edited by Alxprog

2 Years
Discussion Span
Last Post by mike_2000_17

A deduced type traditionally means a template argument type. Like this:

template <typename T>
void foo(T&& t) { /* .. */ };

int i = 0;
foo(i);  // type T will be deduced from this call, from the type of 'i'

However, with the new standard also comes the keyword "auto" which is another form of deduced type, such as this:

int i = 0;

auto&& t = i;  // type 'auto' will be deduced from the type of 'i'

Universal references simply means that when you have a situation such as above (deduced template argument or "auto") followed by double ampersands, then the overall type of the "t" in the above will be whatever is the most appropriate reference type, i.e., const or non-const, lvalue or rvalue reference, depending on whether the variable initializing the reference (incl. passed to the function template) is an lvalue (named variable) or rvalue (temporary value, or moved-from lvalue) and whether it is const or not.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.