Есть код:
std::vector<int> _1, _2;
(_1.empty() ? _1 : _2).push_back(3);
(_1.empty() ? _1 : _2).push_back(3);
По факту выполнения имеем значение в обоих векторах. Т.к. всегда считал что должна возвращаться копия полез читать мануал:
$5.16:
6. Lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are performed
on the second and third operands. After those conversions, one of the following shall hold:
— The second and third operands have the same type; the result is of that type.
If the operands have
class type, the result is a prvalue temporary of the result type, which is copy-initialized from either
the second operand or the third operand depending on the value of the first operand.
Если я правильно понимаю, то стандарт со мной согласен. Или я что-то упустил?
Здравствуйте, saf_e, Вы писали:
_>_>(_1.empty() ? _1 : _2).push_back(3);
_>
в данном случае операнды это ссылки
Здравствуйте, Abyx, Вы писали:
A>Здравствуйте, saf_e, Вы писали:
_>>_>>(_1.empty() ? _1 : _2).push_back(3);
_>>
A>в данном случае операнды это ссылки
Напрашивается вопрос почему?
Здравствуйте, saf_e, Вы писали:
_>$5.16:
_>6.
_>Если я правильно понимаю, то стандарт со мной согласен. Или я что-то упустил?
Да, упустил пункты 1–5. Конкретно нужно смотреть на четвёртый:
4 If the second and third operands are lvalues and have the same type, the result is of that type and is an lvalue
Здравствуйте, watchmaker, Вы писали:
W>Здравствуйте, saf_e, Вы писали:
_>>$5.16:
_>>6.
_>>Если я правильно понимаю, то стандарт со мной согласен. Или я что-то упустил?
W>Да, упустил пункты 1–5. Конкретно нужно смотреть на четвёртый: W>4 If the second and third operands are lvalues and have the same type, the result is of that type and is an lvalue
Спасибо