Merge branch 'feature/#615-addition-of-etl--expected' of https://github.com/ETLCPP/etl into feature/#615-addition-of-etl--expected

# Conflicts:
#	arduino/library-arduino.json
#	arduino/library-arduino.properties
#	include/etl/expected.h
#	include/etl/private/variant_variadic.h
#	include/etl/result.h
#	include/etl/version.h
#	library.json
#	library.properties
#	support/Release notes.txt
#	version.txt
This commit is contained in:
John Wellbelove 2023-02-06 20:25:53 +01:00
commit a710c77d79
2 changed files with 115 additions and 1 deletions

2
.gitignore vendored
View File

@ -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

View File

@ -470,6 +470,120 @@ namespace etl
}
#endif
private:
etl::optional<TError> data;
};
//*****************************************************************************
/// Result type.
/// Specialisation for void error type.
//*****************************************************************************
template<typename TValue>
class result<TValue, void>
{
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;
}
//*******************************************
/// <b>true</b> if result contains a value
//*******************************************
bool has_value() const
{
return data.has_value();
}
//*******************************************
/// <b>true</b> if result contains a value
//*******************************************
bool is_value() const
{
return has_value();
}
//*******************************************
/// <b>true</b> 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<TValue> data;