Пример #1
0
 void swap(expected& rhs)
 {
     if (m_success)
     {
         if (rhs.m_success)
         {
             using std::swap;
             swap(m_value, rhs.m_value);
         }
         else
         {
             auto t = std::move(rhs.spam);
             new (&rhs.m_value) T(std::move(m_value));
             new (&m_excptr) std::exception_ptr(t);
             std::swap(m_success, rhs.m_success);
         }
     }
     else
     {
         if (rhs.m_success)
         {
             rhs.swap(*this);
         }
         else
         {
             m_excptr.swap(rhs.m_excptr);
             std::swap(m_success, rhs.m_success);
         }
     }
 }
Пример #2
0
    void swap( expected & rhs )
    {
        using std::swap;

        if      ( has_value == true  && rhs.has_value == true  ) { swap( contained.value(), rhs.contained.value() ); }
        else if ( has_value == false && rhs.has_value == false ) { swap( contained.error(), rhs.contained.error() ); }
        else if ( has_value == false && rhs.has_value == true  ) { rhs.swap( *this ); }
        else if ( has_value == true  && rhs.has_value == false ) { error_type t = rhs.contained.error();
                                                                   rhs.contained.destruct_error();
                                                                   rhs.contained.construct_value( contained.value() );
                                                                   contained.construct_error( t );
                                                                   swap( has_value, rhs.has_value );
                                                                 }
    }
Пример #3
0
 bool has_unexpected(expected<T, boost::exception_ptr> const& e)
 {
   try {
     if(!e) boost::rethrow_exception(e.error());
   }
   catch(Ex& e)
   {
     return true;
   }
   catch(...)
   {
   }
   return false;
 }
 void operator()(expected<T>& x) {
   if (x)
     (*this)(*x);
   else
     (*this)(x.error());
 }
Пример #5
0
  BOOST_CONSTEXPR bool has_error(expected<T, E> const& e, E1 const& err)
  {
    return (e) ? false : (e.error() == err) ;
 }
 optional<T> make_optional(expected<T> e) {
   if (e.valid()) return optional<T>(*e);
   else return none;
 }
Пример #7
0
void swap( expected<T,E> & x, expected<T,E> & y )
{
  x.swap( y );
}