forked from Alepha/Alepha
Simplify AutoRAII.
MCE permits us to discard the move operations that used to give us the ability to construct these and return them from functions.
This commit is contained in:
49
AutoRAII.h
49
AutoRAII.h
@ -34,49 +34,24 @@ namespace Alepha::Hydrogen
|
|||||||
dtor( value );
|
dtor( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
template
|
|
||||||
<
|
|
||||||
typename AutoRAII_= AutoRAII,
|
|
||||||
typename= std::enable_if_t< std::is_same_v< AutoRAII_, AutoRAII > >,
|
|
||||||
typename= std::enable_if_t< std::is_function_v< decltype( AutoRAII_::dtor ) > >
|
|
||||||
>
|
|
||||||
AutoRAII( AutoRAII &&move )
|
|
||||||
: value()
|
|
||||||
{
|
|
||||||
std::swap( move.dtor, this->dtor );
|
|
||||||
std::swap( move.value, this->value );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename Ctor >
|
template< typename Ctor >
|
||||||
explicit AutoRAII( Ctor ctor, Dtor dtor ) : dtor( std::move( dtor ) ), value( ctor() ) {}
|
explicit AutoRAII( Ctor ctor, Dtor dtor ) : dtor( std::move( dtor ) ), value( ctor() ) {}
|
||||||
|
|
||||||
template
|
|
||||||
<
|
|
||||||
typename AutoRAII_= AutoRAII,
|
|
||||||
typename= std::enable_if_t< std::is_same_v< AutoRAII_, AutoRAII > >,
|
|
||||||
typename= std::enable_if_t< std::is_function_v< decltype( AutoRAII_::dtor ) > >
|
|
||||||
>
|
|
||||||
AutoRAII &operator= ( AutoRAII_ &&move )
|
|
||||||
{
|
|
||||||
std::swap( move.dtor, this->dtor );
|
|
||||||
std::swap( move.value, this->value );
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const T &() const { return value; }
|
operator const T &() const { return value; }
|
||||||
|
|
||||||
template
|
decltype( auto )
|
||||||
<
|
operator *() const
|
||||||
typename T_= T,
|
requires( std::is_pointer_v< T > )
|
||||||
typename= std::enable_if_t< std::is_pointer_v< T_ > >
|
{
|
||||||
>
|
return *value;
|
||||||
decltype( auto ) operator *() const { return *value; }
|
}
|
||||||
|
|
||||||
template
|
decltype( auto )
|
||||||
<
|
operator->() const
|
||||||
typename T_= T,
|
requires( std::is_pointer_v< T > )
|
||||||
typename= std::enable_if_t< std::is_pointer_v< T_ > >
|
{
|
||||||
>
|
return value;
|
||||||
decltype( auto ) operator->() const { return value; }
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename Dtor >
|
template< typename Dtor >
|
||||||
|
|||||||
Reference in New Issue
Block a user