boostorg/optional

`reset()` marked as deprecated

Closed this issue · 4 comments

It should be a mistake that rest() of boost::optional is marked as deprecated because std::optional has reset() [optional.mod].

The story behind this finding

I am working on adding std::optional support for Spirit and it requires rewriting of optional handling. Currently it resets optional with boost::none and I wanted to generalize this (as I do not see a reason why it should handle boost and std optional differently) because I cannot reset std::optional with boost::none_t. The reset() method serves perfectly for this purpose, but the problem is that for some reason boost::optional has reset() marked as deprecated.

Yes, I sympathize with the need. I cannot merge your PR as-is. Since deprecation a maintenance thereof has also been abandoned. It needs unit-testing, marking as noexcept, support in optional<T&>.

It needs unit-testing

// Deinitialization of Initialized Optional
// T::~T() is used to destroy previous value in ob.
set_pending_dtor( ARG(T) ) ;
ob.reset();
check_is_not_pending_dtor( ARG(T) ) ;
check_uninitialized(ob);
// Deinitialization of Uninitialized Optional
// (Dtor is not called this time)
set_pending_dtor( ARG(T) ) ;
ob.reset();
check_is_pending_dtor( ARG(T) ) ;
check_uninitialized(ob);

//
// Case 2: Only one Initialized.
//
reset_throw_on_assign( ARG(T) ) ;
opt0.reset();
opt1.reset(a);
set_throw_on_copy( ARG(T) ) ;
passed = false ;
try
{
// This should attempt to swap optionals and fail at opt0.reset(*opt1)
// Both opt0 and op1 are left unchanged (unswaped)
swap(opt0,opt1);
passed = true ;
}
catch ( ... ) {}
BOOST_TEST(!passed);
check_uninitialized(opt0);
check_initialized(opt1);
check_value(opt1,a,x);

marking as noexcept

void reset() BOOST_NOEXCEPT { destroy(); }

void reset() BOOST_NOEXCEPT { destroy(); }

void reset() BOOST_NOEXCEPT { destroy(); }

void reset() BOOST_NOEXCEPT { ptr_ = 0; }

support in optional<T&>

void reset() BOOST_NOEXCEPT { ptr_ = 0; }

Right. Sorry for too shallow an investigation on my side. I merged the PR with some minor modifications in the documentation.

Thanks!