From Bonita Montero@21:1/5 to All on Mon Nov 22 16:47:03 2021
Look at this code:
#include <iostream>
#include <vector>
using namespace std;
int main( int argc, char *argv )
{
vector<int> vi1, vi2;
for( int i = 0; i != 10; ++i )
vi1.emplace_back( i ),
vi2.emplace_back( i );
vector<int> viR = argc < 2 ? vi1 : move( vi2 );
cout << vi1.size() << endl;
cout << vi2.size() << endl;
cout << viR.size() << endl;
}
If you specify no commandline-parameter viR gets a copy of vi1.
If you specify a commandline-parameter, viR gets the moved con-
tents of vi2. Is this specified behaviour that the result of this
expression is dependent on the path, i.e. it's an lvalue for vi1
and rvalue for vi2 ? What I'm wonderning about is: the result of
the ternary operator should have the same type for all paths. It
would have been more reasonable for me if the compiler would give
an error because of incompatible types.