std::expected<T,E>:: operator->, std::expected<T,E>:: operator*
|
기본 템플릿
|
||
|
constexpr
const
T
*
operator
-
>
(
)
const
noexcept
;
|
(1) | (C++23부터) |
|
constexpr
T
*
operator
-
>
(
)
noexcept
;
|
(2) | (C++23부터) |
|
constexpr
const
T
&
operator
*
(
)
const
&
noexcept
;
|
(3) | (C++23부터) |
|
constexpr
T
&
operator
*
(
)
&
noexcept
;
|
(4) | (C++23부터) |
|
constexpr
const
T
&&
operator
*
(
)
const
&&
noexcept
;
|
(5) | (C++23부터) |
|
constexpr
T
&&
operator
*
(
)
&&
noexcept
;
|
(6) | (C++23부터) |
|
void
부분 특수화
|
||
|
constexpr
void
operator
*
(
)
const
noexcept
;
|
(7) | (C++23부터) |
* this 에 포함된 기대값에 접근합니다.
|
has_value() 가 false 인 경우, 동작은 정의되지 않습니다. |
(C++26까지) |
|
has_value() 가 false 인 경우:
|
(C++26부터) |
목차 |
반환값
val
)
val
참고 사항
이 연산자들은 optional이 기대하는 값을 나타내는지 확인하지 않으며, 사용자는 수동으로
has_value()
또는
operator bool()
를 사용하여 확인할 수 있습니다. 또는 확인된 접근이 필요한 경우,
value()
또는
value_or()
를 사용할 수 있습니다.
예제
#include <cassert> #include <expected> #include <iomanip> #include <iostream> #include <string> int main() { using namespace std::string_literals; std::expected<int, std::string> ex1 = 6; assert(*ex1 == 6); *ex1 = 9; assert(*ex1 == 9); // *ex1 = "error"s; // 오류: ex1은 int 타입의 기대값을 포함함 ex1 = std::unexpected("error"s); // *ex1 = 13; // 미정의 동작: ex1은 예기치 않은 값을 포함함 assert(ex1.value_or(42) == 42); std::expected<std::string, bool> ex2 = "Moon"s; std::cout << "ex2: " << std::quoted(*ex2) << ", size: " << ex2->size() << '\n'; // std::expected 우측값에 operator*를 호출하여 기대값을 "가져올" 수 있음 auto taken = *std::move(ex2); std::cout << "taken " << std::quoted(taken) << "\n" "ex2: " << std::quoted(*ex2) << ", size: " << ex2->size() << '\n'; }
가능한 출력:
ex2: "Moon", size: 4 taken "Moon" ex2: "", size: 0
참고 항목
|
기대값을 반환합니다
(public member function) |
|
|
존재하는 경우 기대값을 반환하고, 그렇지 않으면 다른 값을 반환합니다
(public member function) |
|
|
객체가 기대값을 포함하는지 확인합니다
(public member function) |
|
|
예상치 못한 값을 반환합니다
(public member function) |