
11 Apr
2008
11 Apr
'08
7:14 p.m.
Fernando Cacciola wrote:
Hi Andrey,
Your behavior can be implemented in a non-intrusive way something like that:
template< typename T > void force_koenig_swap(optional< T >& left, optional< T >& right) { bool left_empty = !left; if (left_empty) left = in_place(); bool right_empty = !right; if (right_empty) right = in_place();
using std::swap; swap(left.get(), right.get());
if (left_empty) right = none; if (right_empty) left = none; }
But isn't that, syntax aside, *exactly* the same Thorsten proposed?? I can't tell the difference...
The only difference is that it's not intrusive.