I have a few questions about how boost::optional
works. Let's first do this:
boost::optional<int> i;
i < 3
always equivalent to *i < 3
(and similar for other relational operators)?i < 3
and *i < 3
are undefined? (i
has still not been set to anything)std::cout << i
supposed to print?i = 3
is always the same as *i = 3
. If so, which should I prefer?i
is uninitialized, the first will return true while the second will assert.operator<
clearly indicates that if the lefthand argument is uninitialized it will return true
when the righthand operand is set.operator<<
for optional
so I assume it will return the unspecified-bool-type
conversion and print 1 or 0 (true/false).i
isn't initialized the latter will assert while the former will initialize-and-assign. You should use the one that indicates the semantics you desire.