MCPcopy Create free account
hub / github.com/Profactor/cv-plot / BasicResult

Class BasicResult

CvPlot/ext/catch2/inc/catch.hpp:8912–8954  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8910
8911 template<typename T = void>
8912 class BasicResult : public ResultValueBase<T> {
8913 public:
8914 template<typename U>
8915 explicit BasicResult( BasicResult<U> const &other )
8916 : ResultValueBase<T>( other.type() ),
8917 m_errorMessage( other.errorMessage() )
8918 {
8919 assert( type() != ResultBase::Ok );
8920 }
8921
8922 template<typename U>
8923 static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; }
8924 static auto ok() -> BasicResult { return { ResultBase::Ok }; }
8925 static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; }
8926 static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; }
8927
8928 explicit operator bool() const { return m_type == ResultBase::Ok; }
8929 auto type() const -> ResultBase::Type { return m_type; }
8930 auto errorMessage() const -> std::string { return m_errorMessage; }
8931
8932 protected:
8933 void enforceOk() const override {
8934
8935 // Errors shouldn't reach this point, but if they do
8936 // the actual error message will be in m_errorMessage
8937 assert( m_type != ResultBase::LogicError );
8938 assert( m_type != ResultBase::RuntimeError );
8939 if( m_type != ResultBase::Ok )
8940 std::abort();
8941 }
8942
8943 std::string m_errorMessage; // Only populated if resultType is an error
8944
8945 BasicResult( ResultBase::Type type, std::string const &message )
8946 : ResultValueBase<T>(type),
8947 m_errorMessage(message)
8948 {
8949 assert( m_type != ResultBase::Ok );
8950 }
8951
8952 using ResultValueBase<T>::ResultValueBase;
8953 using ResultBase::m_type;
8954 };
8955
8956 enum class ParseResultType {
8957 Matched, NoMatch, ShortCircuitAll, ShortCircuitSame

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected