| Home | Libraries | People | FAQ | More

### Header <boost/optional/optional.hpp>

#### Synopsis

    // In Header: <boost/optional/optional.hpp>

    namespace boost {

    template <class T>
    class optional
    {
    public :

        typedef T value_type;

        // (If T is of reference type, the parameters and results by reference are by value)

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

    template<class T> inline bool operator == ( optional<T> const& x, optional<T> const& y ) ;

    template<class T> inline bool operator != ( optional<T> const& x, optional<T> const& y ) ;

    template<class T> inline bool operator <  ( optional<T> const& x, optional<T> const& y ) ;

    template<class T> inline bool operator >  ( optional<T> const& x, optional<T> const& y ) ;

    template<class T> inline bool operator <= ( optional<T> const& x, optional<T> const& y ) ;

    template<class T> inline bool operator >= ( optional<T> const& x, optional<T> const& y ) ;

    template<class T> inline bool operator == ( optional<T> const& x, none_t ) noexcept ;

    template<class T> inline bool operator != ( optional<T> const& x, none_t ) noexcept ;

    template<class T> inline optional<T> make_optional ( T const& v ) ;

    template<class T> inline optional<T> make_optional ( bool condition, T const& v ) ;

    template<class T> inline T const& get_optional_value_or ( optional<T> const& opt, T const& default ) ;

    template<class T> inline T const& get ( optional<T> const& opt ) ;

    template<class T> inline T& get ( optional<T> & opt ) ;

    template<class T> inline T const* get ( optional<T> const* opt ) ;

    template<class T> inline T* get ( optional<T>* opt ) ;

    template<class T> inline T const* get_pointer ( optional<T> const& opt ) ;

    template<class T> inline T* get_pointer ( optional<T> & opt ) ;

    template<class T> inline void swap( optional<T>& x, optional<T>& y ) ;

    } // namespace boost