| Home | Libraries | People | FAQ | More

## Synopsis

    namespace boost {

    template<class T>
    class optional
    {
        public :

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

        optional () ;

        optional ( none_t ) ;

        optional ( T const& v ) ;

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

        optional ( optional const& rhs ) ;

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

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

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

        optional& operator = ( none_t ) ;

        optional& operator = ( T const& v ) ;

        optional& operator = ( optional const& rhs ) ;

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

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

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

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

        // [new in 1.34]
        T const& get_value_or( T const& default ) const ;

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

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

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

        operator unspecified-bool-type() const ;

        bool operator!() const ;

        // deprecated methods

        // (deprecated)
        void reset() ;

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

        // (deprecated)
        bool is_initialized() 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 ) ;

    // [new in 1.34]
    template<class T> inline optional<T> make_optional ( T const& v ) ;

    // [new in 1.34]
    template<class T> inline optional<T> make_optional ( bool condition, T const& v ) ;

    // [new in 1.34]
    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