Skip to content

Commit

Permalink
Merge branch 'feature/#615-addition-of-etl--expected' of https://gith…
Browse files Browse the repository at this point in the history
…ub.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
  • Loading branch information
John Wellbelove committed Feb 6, 2023
2 parents 4c92670 + 5fb3e4c commit a710c77
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
114 changes: 114 additions & 0 deletions include/etl/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a710c77

Please sign in to comment.