Reputation: 447
Chapter 4.7 of the book C++ Primer says:
That result of the conditional operator is an lvalue if both expressions are lvalues or if they convert to a common lvalue type. Otherwise the result is an rvalue.
Can someone give me an example of a case where the operator yields an lvalue using a conversion to a common lvalue type?
Upvotes: 0
Views: 67
Reputation: 97815
Sure:
#include <type_traits>
int main(int argc, char **argv) {
struct A {} a;
struct B : A {} b;
static_assert(std::is_same_v<A &, decltype(argc > 0 ? a : b)>);
}
Upvotes: 1