std::experimental::optional<T>:: optional
|
constexpr
optional
(
)
noexcept
;
constexpr optional ( std:: experimental :: nullopt_t ) noexcept ; |
(1) | (라이브러리 fundamentals TS) |
|
optional
(
const
optional
&
other
)
;
|
(2) | (라이브러리 fundamentals TS) |
|
optional
(
optional
&&
other
)
noexcept
(
/* 아래 참조 */
)
;
|
(3) | (라이브러리 fundamentals TS) |
|
constexpr
optional
(
const
T
&
value
)
;
|
(4) | (라이브러리 fundamentals TS) |
|
constexpr
optional
(
T
&&
value
)
;
|
(5) | (라이브러리 fundamentals TS) |
|
template
<
class
...
Args
>
constexpr explicit optional ( std:: experimental :: in_place_t , Args && ... args ) ; |
(6) | (라이브러리 fundamentals TS) |
|
template
<
class
U,
class
...
Args
>
constexpr
explicit
optional
(
std::
experimental
::
in_place_t
,
|
(7) | (라이브러리 fundamentals TS) |
새로운
optional
객체를 생성합니다.
T
타입의 객체를
*
other
표현식으로 초기화합니다. 만약
other
가 값을 포함하고 있지 않다면,
값을 포함하지 않는
객체를 생성합니다.
T
타입의 객체를
std
::
move
(
*
other
)
표현식으로 초기화하며,
그리고
other
를 비우지
않습니다
: 이동된 optional은 여전히
값을 포함합니다
, 하지만 값 자체는 이동되었습니다. 만약
other
가 값을 포함하지 않는다면, 값을
포함하지 않는
객체를 생성합니다.
T
타입의 객체를
직접 초기화
(단 직접 목록 초기화는 아님) 방식으로
value
표현식으로 초기화하는 것처럼 초기화됩니다. 이 생성자는 직접 초기화로 선택된
T
의 생성자가
constexpr
일 경우
constexpr
입니다.
T
타입의 객체를
직접 초기화
(단 직접 목록 초기화는 아님) 방식으로
std
::
move
(
value
)
표현식으로 초기화한 것처럼 초기화됩니다. 이 생성자는 직접 초기화로 선택된
T
의 생성자가
constexpr
일 경우
constexpr
입니다.
T
타입의 객체를
직접 초기화
(단 직접 목록 초기화는 제외)하는 것처럼 초기화됩니다.
T
타입의 객체를
직접 초기화
(단 직접 목록 초기화는 제외)하는 것처럼 초기화됩니다.
std::
is_constructible
<
T,
std::
initializer_list
<
U
>
&
, Args
&&
...
>
::
value
!
=
true
인 경우 이 함수는 오버로드 해결에 참여하지 않습니다.
목차 |
매개변수
| other | - |
포함된 값을 복사할 다른
optional
객체
|
| value | - | 포함된 값을 초기화할 값 |
| args... | - | 포함된 값을 초기화할 인수들 |
| ilist | - | 포함된 값을 초기화할 초기화자 리스트 |
| 타입 요구사항 | ||
-
T
는 오버로드 (2,4) 사용을 위해
CopyConstructible
요구사항을 충족해야 함
|
||
-
T
는 오버로드 (3,5) 사용을 위해
MoveConstructible
요구사항을 충족해야 함
|
||
예외
T
의 생성자가 던지는 모든 예외를 발생시킵니다.
T
의 생성자가 던지는 모든 예외를 전파합니다. 다음과 같은
noexcept
선언을 가집니다:
T
의 생성자가 던지는 모든 예외를 발생시킵니다.
예제
#include <experimental/optional> #include <iostream> #include <string> int main() { std::experimental::optional<int> o1, // 비어 있음 o2 = 1, // 우측값으로 초기화 o3 = o2; // 복사 생성자 std::experimental::optional<std::string> o4(std::experimental::in_place, {'a', 'b', 'c'}); std::cout << *o2 << ' ' << *o3 << ' ' << *o4 << '\n'; }
출력:
1 1 abc
참고 항목
optional
객체를 생성합니다
(함수 템플릿) |