Start New Discussion within our Software Development Community

Hi!
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.

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.