mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 02:08:09 +08:00
add unwrap_or to result
This commit is contained in:
@@ -394,6 +394,25 @@ struct result
|
|||||||
return std::move(this->succ.value);
|
return std::move(this->succ.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
value_type& unwrap_or(U& opt) &
|
||||||
|
{
|
||||||
|
if(is_err()) {return opt;}
|
||||||
|
return this->succ.value;
|
||||||
|
}
|
||||||
|
template<typename U>
|
||||||
|
value_type const& unwrap_or(U const& opt) const&
|
||||||
|
{
|
||||||
|
if(is_err()) {return opt;}
|
||||||
|
return this->succ.value;
|
||||||
|
}
|
||||||
|
template<typename U>
|
||||||
|
value_type&& unwrap_or(U&& opt) &&
|
||||||
|
{
|
||||||
|
if(is_err()) {return std::move(opt);}
|
||||||
|
return std::move(this->succ.value);
|
||||||
|
}
|
||||||
|
|
||||||
error_type& unwrap_err() &
|
error_type& unwrap_err() &
|
||||||
{
|
{
|
||||||
if(is_ok()) {throw std::runtime_error("toml::result: bad unwrap_err");}
|
if(is_ok()) {throw std::runtime_error("toml::result: bad unwrap_err");}
|
||||||
|
Reference in New Issue
Block a user