#include #include using namespace std ; //-------------------------------------------------------- template // works, but auto function1(MyVector& c1, Index i1) // requires -> decltype( c1[i1] ) { return c1[i1] ; } template // works, but auto function2(MyVector& c1, Index i1) // requires { return c1[i1] ; } template // works, but auto& function2a(MyVector& c1, Index i1) // requires { return c1[i1] ; } template // works, but decltype(auto) function3(MyVector& c1, Index i1) // requires { return c1[i1] ; } //-------------------------------------------------------- int main() { vector v1 ; v1.push_back( 100 ) ; v1.push_back( 101 ) ; cout << "function1( v1, 0 ) " << function1( v1, 0 ) << endl ; function1( v1, 0 ) = 101 ; //valid cout << "function2( v1, 0 ) " << function2( v1, 0 ) << endl ; //function2( v1, 0 ) = 101 ; //invalid //auto by itself takes out the reference function2a( v1, 0 ) = 102 ; //valid cout << "function3( v1, 0 ) " << function3( v1, 0 ) << endl ; function3( v1, 0 ) = 101 ; //valid return 0 ; } //--------------------------------------------------------