diff --git a/.gitignore b/.gitignore index f44872fb0..d9577b4cb 100644 --- a/.gitignore +++ b/.gitignore @@ -363,8 +363,8 @@ examples/ArmTimerCallbacks - C++/ArmTimerCallbacks.uvoptx test/vs2022/.vs test/vs2022/random_clcg.csv test/vs2022/random_hash.csv -test/vs2022/random_lcg.csv test/vs2022/random_lsfr.csv +test/vs2022/random_lcg.csv test/vs2022/random_mwc.csv test/vs2022/random_pcg.csv test/vs2022/random_xorshift.csv diff --git a/include/etl/result.h b/include/etl/result.h index 0ddf637a6..2b8e0ae11 100644 --- a/include/etl/result.h +++ b/include/etl/result.h @@ -470,6 +470,120 @@ namespace etl } #endif + private: + + etl::optional data; + }; + + //***************************************************************************** + /// Result type. + /// Specialisation for void error type. + //***************************************************************************** + template + class result + { + public: + + //******************************************* + /// Default Constructor + //******************************************* + result() + { + } + + //******************************************* + /// Copy constructor + //******************************************* + result(const result& other) + : data(other.data) + { + } + + //******************************************* + /// Move constructor + //******************************************* + result(result&& other) + : data(etl::move(other.data)) + { + } + + //******************************************* + /// Construct from error + //******************************************* + result(const TValue& value) + : data(value) + { + } + + //******************************************* + /// Move construct from error + //******************************************* + result(TValue&& value) + : data(etl::move(value)) + { + } + + //******************************************* + /// Copy assign from error + //******************************************* + result& operator =(const TValue& value) + { + data = value; + return *this; + } + + //******************************************* + /// Move assign from error + //******************************************* + result& operator =(TValue&& value) + { + data = etl::move(value); + return *this; + } + + //******************************************* + /// true if result contains a value + //******************************************* + bool has_value() const + { + return data.has_value(); + } + + //******************************************* + /// true if result contains a value + //******************************************* + bool is_value() const + { + return has_value(); + } + + //******************************************* + /// true if result contains an error + //******************************************* + bool is_error() const + { + return !has_value(); + } + + //******************************************* + /// Returns a const reference to the error. + /// Undefined if the result does not contain an error. + //******************************************* + const TValue& value() const + { + return data.value(); + } + + //******************************************* + /// Returns an rvalue reference to the error. + /// Undefined if the result does not contain an error. + //******************************************* + TValue&& value() + { + return etl::move(data.value()); + } +#endif + private: etl::optional data;