If you have a function that returns a temporary one that cannot be moved.
Foo some_function();
auto&& f = some_function();
. auto f = some_function(); ( ), ( ).
auto&& r, lvalue , , , lvalue.
"-":
for( auto&& x : some_range )
auto&& x = *it;.
lvalue , - Widget const&, .
, . , , a+b+c*d
auto&& c_times_d = d*d;
auto&& b_plus_c_times_d = b + decltype(c_times_d)c_times_d;
auto&& c_plus_b_plus_c_times_d = c + decltype(b_plus_c_times_d)b_plus_c_times_d;
, , : .
, . ( , -> , , , .)
auto&&, : " - , , ", . auto - .
.
Foo const& a(Foo*);
Bar a(Bar*);
template<class T>
auto do_stuff( T*ptr ) {
auto&& x = a(ptr);
}
, Bar*, , Foo* do_stuff, const&.
.
, , auto&& . , , :
struct Foo {
Foo(&&)=delete;
Foo(int x) { std::cout << "Foo " << x << " constructed\n";
};
Foo test() {
return {3};
}
int main() {
auto&& f = test();
}