Files
2025-10-25 03:02:53 +03:00

5.9 KiB
Raw Permalink Blame History

[optional.ref.ctor]

22 General utilities library [utilities]

22.5 Optional objects [optional]

22.5.4 Partial specialization of optional for reference types [optional.optional.ref]

22.5.4.2 Constructors [optional.ref.ctor]

🔗

template<class Arg> constexpr explicit optional(in_place_t, Arg&& arg);

1

#

Constraints:

is_constructible_v<T&, Arg> is true, and

reference_constructs_from_temporary_v<T&, Arg> is false.

2

#

Effects: Equivalent to: convert-ref-init-val(std::forward(arg)).

3

#

Postconditions: *this contains a value.

🔗

template<class U> constexpr explicit(!is_convertible_v<U, T&>) optional(U&& u) noexcept(is_nothrow_constructible_v<T&, U>);

4

#

Constraints:

is_same_v<remove_cvref_t, optional> is false,

is_same_v<remove_cvref_t, in_place_t> is false, and

is_constructible_v<T&, U> is true.

5

#

Effects: Equivalent to: convert-ref-init-val(std::forward(u)).

6

#

Postconditions: *this contains a value.

7

#

Remarks: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U> is true.

🔗

template<class U> constexpr explicit(!is_convertible_v<U&, T&>) optional(optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, U&>);

8

#

Constraints:

is_same_v<remove_cv_t, optional> is false,

is_same_v<T&, U> is false, and

is_constructible_v<T&, U&> is true.

9

#

Effects: Equivalent to:if (rhs.has_value()) convert-ref-init-val(*rhs);

10

#

Remarks: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U&> is true.

🔗

template<class U> constexpr explicit(!is_convertible_v<const U&, T&>) optional(const optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, const U&>);

11

#

Constraints:

is_same_v<remove_cv_t, optional> is false,

is_same_v<T&, U> is false, and

is_constructible_v<T&, const U&> is true.

12

#

Effects: Equivalent to:if (rhs.has_value()) convert-ref-init-val(*rhs);

13

#

Remarks: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, const U&> is true.

🔗

template<class U> constexpr explicit(!is_convertible_v<U, T&>) optional(optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, U>);

14

#

Constraints:

is_same_v<remove_cv_t, optional> is false,

is_same_v<T&, U> is false, and

is_constructible_v<T&, U> is true.

15

#

Effects: Equivalent to:if (rhs.has_value()) convert-ref-init-val(*std::move(rhs));

16

#

Remarks: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U> is true.

🔗

template<class U> constexpr explicit(!is_convertible_v<const U, T&>) optional(const optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, const U>);

17

#

Constraints:

is_same_v<remove_cv_t, optional> is false,

is_same_v<T&, U> is false, and

is_constructible_v<T&, const U> is true.

18

#

Effects: Equivalent to:if (rhs.has_value()) convert-ref-init-val(*std::move(rhs));

19

#

Remarks: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, const U> is true.