mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
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:
commit
a710c77d79
2
.gitignore
vendored
2
.gitignore
vendored
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user