diff --git a/alib2abstraction/src/abstraction/ValueOperationAbstraction.hpp b/alib2abstraction/src/abstraction/ValueOperationAbstraction.hpp index 52173501d131da8815b50c9cdbfbd06a9522bcf3..e2d8cdbe14baa3b8980d17b06136b513a51f375a 100644 --- a/alib2abstraction/src/abstraction/ValueOperationAbstraction.hpp +++ b/alib2abstraction/src/abstraction/ValueOperationAbstraction.hpp @@ -11,7 +11,6 @@ #include <alib/tuple> #include <alib/memory> #include <alib/typeindex> -#include <alib/variant> #include <abstraction/OperationAbstraction.hpp> #include <abstraction/ValueProvider.hpp> @@ -27,14 +26,14 @@ template < class ReturnType > class ValueOperationAbstraction : public OperationAbstraction, public ValueProvider < ReturnType >, public ValueProvider < ReturnType & >, public ValueProvider < const ReturnType & >, public ValueProvider < ReturnType && >, public ValueProvider < const ReturnType && > { protected: virtual ReturnType & getData ( ) const override { - return m_data.template get < ReturnType > ( ); + return m_data.value ( ); } virtual const ReturnType & getConstData ( ) const override { - return m_data.template get < ReturnType > ( ); + return m_data.value ( ); } - mutable ext::variant < void, ReturnType > m_data; + mutable std::optional < ReturnType > m_data; public: template < typename ... ParamTypes, typename Callable > @@ -44,7 +43,7 @@ public: } virtual bool isReady ( ) const override { - return m_data.template is < ReturnType > ( ); + return ( bool ) m_data; } virtual ext::type_index getReturnTypeIndex ( ) const override { @@ -67,14 +66,14 @@ template < class ReturnType > class ValueOperationAbstraction < ReturnType & > : public OperationAbstraction, public ValueProvider < ReturnType & >, public ValueProvider < const ReturnType & >, public ValueProvider < ReturnType && >, public ValueProvider < const ReturnType && > { protected: virtual ReturnType & getData ( ) const override { - return m_data.template get < std::reference_wrapper < ReturnType > > ( ).get ( ); + return m_data->get ( ); } virtual const ReturnType & getConstData ( ) const override { - return m_data.template get < std::reference_wrapper < ReturnType > > ( ).get ( ); + return m_data->get ( ); } - mutable ext::variant < void, std::reference_wrapper < ReturnType > > m_data; + mutable std::optional < std::reference_wrapper < ReturnType > > m_data; public: template < typename ... ParamTypes, typename Callable > @@ -84,7 +83,7 @@ public: } virtual bool isReady ( ) const override { - return m_data.template is < std::reference_wrapper < ReturnType > > ( ); + return ( bool ) m_data; } virtual ext::type_index getReturnTypeIndex ( ) const override { @@ -107,10 +106,10 @@ template < class ReturnType > class ValueOperationAbstraction < const ReturnType & > : public OperationAbstraction, public ValueProvider < const ReturnType & >, public ValueProvider < const ReturnType && > { protected: virtual const ReturnType & getConstData ( ) const override { - return m_data.template get < std::reference_wrapper < const ReturnType > > ( ).get ( ); + return m_data->get ( ); } - mutable ext::variant < void, std::reference_wrapper < const ReturnType > > m_data; + mutable std::optional < std::reference_wrapper < const ReturnType > > m_data; public: template < typename ... ParamTypes, typename Callable > @@ -120,7 +119,7 @@ public: } virtual bool isReady ( ) const override { - return m_data.template is < std::reference_wrapper < const ReturnType > > ( ); + return ( bool ) m_data; } virtual ext::type_index getReturnTypeIndex ( ) const override { @@ -143,14 +142,14 @@ template < class ReturnType > class ValueOperationAbstraction < ReturnType && > : public OperationAbstraction, public ValueProvider < ReturnType & >, public ValueProvider < const ReturnType & >, public ValueProvider < ReturnType && >, public ValueProvider < const ReturnType && > { protected: virtual ReturnType & getData ( ) const override { - return m_data.template get < std::reference_wrapper < ReturnType > > ( ).get ( ); + return m_data->get ( ); } virtual const ReturnType & getConstData ( ) const override { - return m_data.template get < std::reference_wrapper < ReturnType > > ( ).get ( ); + return m_data->get ( ); } - mutable ext::variant < void, std::reference_wrapper < ReturnType > > m_data; + mutable std::optional < std::reference_wrapper < ReturnType > > m_data; public: template < typename ... ParamTypes, typename Callable > @@ -162,7 +161,7 @@ public: } virtual bool isReady ( ) const override { - return m_data.template is < std::reference_wrapper < ReturnType > > ( ); + return ( bool ) m_data; } virtual ext::type_index getReturnTypeIndex ( ) const override { @@ -185,10 +184,10 @@ template < class ReturnType > class ValueOperationAbstraction < const ReturnType && > : public OperationAbstraction, public ValueProvider < const ReturnType & >, public ValueProvider < const ReturnType && > { protected: virtual const ReturnType & getConstData ( ) const override { - return m_data.template get < std::reference_wrapper < const ReturnType > > ( ).get ( ); + return m_data->get ( ); } - mutable ext::variant < void, std::reference_wrapper < const ReturnType > > m_data; + mutable std::optional < std::reference_wrapper < const ReturnType > > m_data; public: template < typename ... ParamTypes, typename Callable > @@ -200,7 +199,7 @@ public: } virtual bool isReady ( ) const override { - return m_data.template is < std::reference_wrapper < const ReturnType > > ( ); + return ( bool ) m_data; } virtual ext::type_index getReturnTypeIndex ( ) const override { diff --git a/alib2abstraction/src/abstraction/WrapperAbstraction.hpp b/alib2abstraction/src/abstraction/WrapperAbstraction.hpp index 3634fcc7a1bff99a221e299ff81fb8c225258567..28311daad4e24dfa55095cc67b8dcce07540f7f7 100644 --- a/alib2abstraction/src/abstraction/WrapperAbstraction.hpp +++ b/alib2abstraction/src/abstraction/WrapperAbstraction.hpp @@ -9,6 +9,7 @@ #define _WRAPPER_ABSTRACTION_HPP_ #include <abstraction/OperationAbstraction.hpp> +#include <optional> namespace abstraction { @@ -17,7 +18,7 @@ class BaseWrapperAbstraction : public OperationAbstraction { protected: std::function < std::shared_ptr < OperationAbstraction > ( ParamTypes ... ) > m_WrapperFinder; - ext::variant < void, std::shared_ptr < OperationAbstraction > > m_data; + std::optional < std::shared_ptr < OperationAbstraction > > m_data; ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > m_params; public: @@ -92,7 +93,7 @@ public: } virtual bool isReady ( ) const override { - return m_data.template is < std::shared_ptr < OperationAbstraction > > ( ) && m_data.template get < std::shared_ptr < OperationAbstraction > > ( )->isReady ( ); + return ( bool ) m_data && m_data.value ( )->isReady ( ); } virtual bool cached ( ) const override { @@ -105,7 +106,7 @@ public: virtual std::shared_ptr < abstraction::OperationAbstraction > getProxyAbstraction ( ) override { if ( this->isReady ( ) ) - return this->m_data.template get < std::shared_ptr < OperationAbstraction > > ( )->getProxyAbstraction ( ); + return this->m_data.value ( )->getProxyAbstraction ( ); else throw std::domain_error ( "Proxy abstraction not avaiable before evaluation." ); } @@ -118,10 +119,10 @@ public: } virtual bool run ( ) override { - if ( this->m_data.template is < void > ( ) ) + if ( ! this->m_data ) this->m_data = abstraction::apply < ParamTypes ... > ( this->m_WrapperFinder, this->m_params ); - std::shared_ptr < OperationAbstraction > & abstraction = this->m_data.template get < std::shared_ptr < OperationAbstraction > > ( ); + std::shared_ptr < OperationAbstraction > & abstraction = this->m_data.value ( ); if ( abstraction->getReturnTypeIndex ( ) != this->getReturnTypeIndex ( ) ) throw std::domain_error ( "Expected and provided types do not match" ); @@ -151,10 +152,10 @@ public: } virtual bool run ( ) override { - if ( this->m_data.template is < void > ( ) ) + if ( ! this->m_data ) this->m_data = abstraction::apply < ParamTypes ... > ( this->m_WrapperFinder, this->m_params ); - std::shared_ptr < OperationAbstraction > & abstraction = this->m_data.template get < std::shared_ptr < OperationAbstraction > > ( ); + std::shared_ptr < OperationAbstraction > & abstraction = this->m_data.value ( ); for ( unsigned index = 0; index < sizeof ... ( ParamTypes ); ++ index ) abstraction->attachInput ( this->m_params [ index ].first, index, this->m_params [ index ].second, true ); @@ -167,7 +168,7 @@ public: virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override { if ( this->isReady ( ) ) - return this->m_data.template get < std::shared_ptr < OperationAbstraction > > ( )->getProxyAbstraction ( )->getRuntimeReturnTypeIndex ( ); + return this->m_data.value ( )->getProxyAbstraction ( )->getRuntimeReturnTypeIndex ( ); else throw std::domain_error ( "Runtime type unknown before evaluation." ); }