Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Optional Values

template <class T>
class optional
{
public :

    typedef T         value_type ;
    typedef T &       reference_type ;
    typedef T const&  reference_const_type ;
    typedef T &&      rval_reference_type ;
    typedef T *       pointer_type ;
    typedef T const*  pointer_const_type ;

    optional () noexcept ; R

    optional ( none_t ) noexcept ; R

    optional ( T const& v ) ; R

    optional ( T&& v ) ; R

    optional ( bool condition, T const& v ) ; R

    optional ( optional const& rhs ) ; R

    optional ( optional&& rhs ) noexcept(see below) ; R

    template<class U> explicit optional ( optional<U> const& rhs ) ; R

    template<class U> explicit optional ( optional<U>&& rhs ) ; R

    template<class... Args> explicit optional ( in_place_init_t, Args&&... args ) ; R

    template<class... Args> explicit optional ( in_place_init_if_t, bool condition, Args&&... args ) ; R

    template<class InPlaceFactory> explicit optional ( InPlaceFactory const& f ) ; R

    template<class TypedInPlaceFactory> explicit optional ( TypedInPlaceFactory const& f ) ; R

    optional& operator = ( none_t ) noexcept ; R

    optional& operator = ( T const& v ) ; R

    optional& operator = ( T&& v ) ; R

    optional& operator = ( optional const& rhs ) ; R

    optional& operator = ( optional&& rhs ) noexcept(see below) ; R

    template<class U> optional& operator = ( optional<U> const& rhs ) ; R

    template<class U> optional& operator = ( optional<U>&& rhs ) ; R

    template<class... Args> void emplace ( Args&&... args ) ; R

    template<class InPlaceFactory> optional& operator = ( InPlaceFactory const& f ) ; R

    template<class TypedInPlaceFactory> optional& operator = ( TypedInPlaceFactory const& f ) ; R

    T const& get() const ; R
    T&       get() ; R

    T const* operator ->() const ; R
    T*       operator ->() ; R

    T const& operator *() const& ; R
    T&       operator *() & ; R
    T&&      operator *() && ; R

    T const& value() const& ; R
    T&       value() & ; R
    T&&      value() && ; R

    template<class U> T value_or( U && v ) const& ; R
    template<class U> T value_or( U && v ) && ; R

    template<class F> T value_or_eval( F f ) const& ; R
    template<class F> T value_or_eval( F f ) && ; R

    template<class F> auto map( F f ) const& -> see below; R
    template<class F> auto map( F f ) & -> see below; R
    template<class F> auto map( F f ) && -> see below; R

    template<class F> auto flat_map( F f ) const& -> see below; R
    template<class F> auto flat_map( F f ) & -> see below; R
    template<class F> auto flat_map( F f ) && -> see below; R

    T const* get_ptr() const ; R
    T*       get_ptr() ; R

    bool has_value() const noexcept ; R

    explicit operator bool() const noexcept ; R

    bool operator!() const noexcept ; R

    void reset() noexcept ; R

    // deprecated methods

    // (deprecated)
    void reset ( T const& ) ; R

    // (deprecated)
    bool is_initialized() const ; R

    // (deprecated)
    T const& get_value_or( T const& default ) const ; R
};

PrevUpHomeNext