Files
cppdraft_translate/cppdraft/optional/observe.md
2025-10-25 03:02:53 +03:00

4.6 KiB
Raw Blame History

[optional.observe]

22 General utilities library [utilities]

22.5 Optional objects [optional]

22.5.3 Class template optional [optional.optional]

22.5.3.7 Observers [optional.observe]

🔗

constexpr const T* operator->() const noexcept; constexpr T* operator->() noexcept;

1

#

Hardened preconditions: has_value() is true.

2

#

Returns: val.

3

#

Remarks: These functions are constexpr functions.

🔗

constexpr const T& operator*() const & noexcept; constexpr T& operator*() & noexcept;

4

#

Hardened preconditions: has_value() is true.

5

#

Returns: *val.

6

#

Remarks: These functions are constexpr functions.

🔗

constexpr T&& operator*() && noexcept; constexpr const T&& operator*() const && noexcept;

7

#

Hardened preconditions: has_value() is true.

8

#

Effects: Equivalent to: return std::move(*val);

🔗

constexpr explicit operator bool() const noexcept;

9

#

Returns: true if and only if *this contains a value.

10

#

Remarks: This function is a constexpr function.

🔗

constexpr bool has_value() const noexcept;

11

#

Returns: true if and only if *this contains a value.

12

#

Remarks: This function is a constexpr function.

🔗

constexpr const T& value() const &; constexpr T& value() &;

13

#

Effects: Equivalent to:return has_value() ? *val : throw bad_optional_access();

🔗

constexpr T&& value() &&; constexpr const T&& value() const &&;

14

#

Effects: Equivalent to:return has_value() ? std::move(*val) : throw bad_optional_access();

🔗

template<class U = remove_cv_t<T>> constexpr T value_or(U&& v) const &;

15

#

Mandates: is_copy_constructible_v && is_convertible_v<U&&, T> is true.

16

#

Effects: Equivalent to:return has_value() ? **this : static_cast(std::forward(v));

🔗

template<class U = remove_cv_t<T>> constexpr T value_or(U&& v) &&;

17

#

Mandates: is_move_constructible_v && is_convertible_v<U&&, T> is true.

18

#

Effects: Equivalent to:return has_value() ? std::move(**this) : static_cast(std::forward(v));