Bonita Montero
unread,Nov 22, 2021, 10:47:21 AM11/22/21You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
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.