Constructors

Synopses

Declared in <beman/optional/optional.hpp>

Default constructs an empty optional.

constexpr
optional() noexcept;

Copy constructs the value from rhs if it has one.

constexpr
optional(optional const& rhs)
requires std::is_copy_constructible_v<T> && std::is_trivially_copy_constructible_v<T> = default;

Copy constructs the value from rhs if it has one.

constexpr
optional(optional const& rhs)
requires std::is_copy_constructible_v<T> && (!std::is_trivially_copy_constructible_v<T>);

Constructs the value from rhs if it has one.

template<class U>
constexpr
explicit(!std::is_convertible_v<U, T>)
optional(optional<U> const& rhs)
requires (detail::enable_from_other<T, U, const U&>);

Move constructs the value from rhs if it has one.

constexpr
optional(optional&& rhs)
requires std::is_move_constructible_v<T> && std::is_trivially_move_constructible_v<T> = default;

Move constructs the value from rhs if it has one.

constexpr
optional(optional&& rhs) noexcept(std::is_nothrow_move_constructible_v<T>)
requires std::is_move_constructible_v<T> && (!std::is_trivially_move_constructible_v<T>);

Constructs the value from rhs if it has one.

template<class U>
constexpr
explicit(!std::is_convertible_v<U, T>)
optional(optional<U>&& rhs)
requires (detail::enable_from_other<T, U, U &&>);

Constructs an empty optional.

constexpr
optional(nullopt_t rhs) noexcept;

Constructs the value from u, forwarding it if necessary.

template<class U = T>
constexpr
explicit(!std::is_convertible_v<U, T>)
optional(U&& u)
requires detail::enable_forward_value<T, U>;

Constructs the value in‐place using the given arguments.

template<class... Args>
constexpr
explicit
optional(
    in_place_t tag,
    Args&&... args)
requires std::is_constructible_v<T, Args...>;

Constructs the value in‐place using the given arguments.

template<
    class U,
    class... Args>
constexpr
explicit
optional(
    in_place_t tag,
    std::initializer_list<U> il,
    Args&&... args)
requires std::is_constructible_v<T, std::initializer_list<U>&, Args&&...>;

Parameters

Name

Description

rhs

The optional to copy from.

u

The value to construct the contained value from.

tag

The in‐place construction tag.

args

The arguments to use for in‐place construction.

il

The initializer list to use for in‐place construction.

Created with MrDocs