This is an academic question. The std::optional<T>
type has a T && value() &&
method. I have the following definitions:
class A { ... };
void f(A &&a);
And the following program:
std::optional<A> optA;
optA = A(1337);
f(std::move(optA).value()); // OPTION 1
f(std::move(optA.value())); // OPTION 2
std::cout << optA.has_value() << std::endl;
Is there any meaningful difference between OPTION 1 and OPTION 2? For OPTION 1 will I have 1
, 0
or unspecified as output? According to my tests has_value() remained true in both cases.
Is there any possible situation where value() &&
makes a difference over std::move
and value()
?