From f54ef61e6da9e114f9742dcffd7d23319e0fc4e5 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 25 Oct 2023 22:37:28 -0400 Subject: [PATCH] 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. --- AutoRAII.h | 49 ++++++++++++------------------------------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/AutoRAII.h b/AutoRAII.h index 84d4273..03509db 100644 --- a/AutoRAII.h +++ b/AutoRAII.h @@ -34,49 +34,24 @@ namespace Alepha::Hydrogen 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 > 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; } - template - < - typename T_= T, - typename= std::enable_if_t< std::is_pointer_v< T_ > > - > - decltype( auto ) operator *() const { return *value; } + decltype( auto ) + operator *() const + requires( std::is_pointer_v< T > ) + { + return *value; + } - template - < - typename T_= T, - typename= std::enable_if_t< std::is_pointer_v< T_ > > - > - decltype( auto ) operator->() const { return value; } + decltype( auto ) + operator->() const + requires( std::is_pointer_v< T > ) + { + return value; + } }; template< typename Dtor >