- expected[meta header]
- function template[meta id-type]
- std[meta namespace]
- expected.void[meta class]
- cpp23[meta cpp]
// expected<cv void, E>部分特殊化
template<class G = E> constexpr E error_or(G&& e) const &; // (1)
template<class G = E> constexpr E error_or(G&& e) &&; // (2)
エラー値もしくは指定された値を取得する。
- (1) :
is_copy_constructible_v
<E> == true &&
is_convertible_v
<G, E> == true
- (2) :
is_move_constructible_v
<E> == true &&
is_convertible_v
<G, E> == true
- (1) :
has_value()
?
std::forward
<G>(e) :
error()
- (2) :
has_value()
?
std::forward
<G>(e) :
std::move
(
error()
)
#include <expected>
#include <iostream>
#include <string>
int main()
{
std::expected<void, std::string> x;
std::cout << x.error_or("-") << std::endl;
std::expected<void, std::string> y = std::unexpected{"ERR"};
std::cout << y.error_or("-") << std::endl;
}
- error_or[color ff0000]
- std::unexpected[link ../unexpected.md]
-
ERR
- C++23
- Clang: ??
- GCC: 13.0 [mark verified]
- ICC: ??
- Visual C++: ??