| Home | Libraries | People | FAQ | More

#### 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 ;

        optional ( none_t ) noexcept ;

        optional ( T const& v ) ;

        optional ( T&& v ) ;

        // [new in 1.34]
        optional ( bool condition, T const& v ) ;

        optional ( optional const& rhs ) ;

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

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

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

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

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

        optional& operator = ( none_t ) noexcept ;

        optional& operator = ( T const& v ) ;

        optional& operator = ( T&& v ) ;

        optional& operator = ( optional const& rhs ) ;

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

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

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

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

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

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

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

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

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

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

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

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

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

        explicit operator bool() const noexcept ;

        bool operator!() const noexcept ;

        // deprecated methods

        // (deprecated)
        void reset() noexcept ;

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

        // (deprecated)
        bool is_initialized() const ;

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