Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class any

boost::any — A class whose instances can hold instances of any type that satisfies ValueType requirements.

Synopsis

// In header: <boost/any.hpp>


class any {
public:
  // construct/copy/destruct
  () ;
  template<typename ValueType> ();
  (any &);
  (any &&) ;
  template<typename ValueType> 
    (, 
        any &,  = , 
         = );
  any & (any &);
  any & (any &&) ;
  template<typename ValueType> any & ();
  ~();

  // public member functions
  any & (any &) ;
   () ;
   () ;
   () ;
};

Description

any public construct/copy/destruct

  1. () ;

    Postconditions:

    this->empty() is true.

  2. template<typename ValueType> ( value);

    Makes a copy of value, so that the initial content of the new instance is equivalent in both type and value to value.

    Throws:

    std::bad_alloc or any exceptions arising from the copy constructor of the contained type.
  3. (any & other);

    Copy constructor that copies content of other into new instance, so that any content is equivalent in both type and value to the content of other, or empty if other is empty.

    Throws:

    May fail with a std::bad_alloc exception or any exceptions arising from the copy constructor of the contained type.
  4. (any && other) ;

    Move constructor that moves content of other into new instance and leaves other empty.

    Requires:

    C++11 compatible compiler

    Postconditions:

    other->empty() is true

    Throws:

    Nothing.
  5. template<typename ValueType> 
      ( value, 
          any &,  = , 
           = );

    Forwards value, so that the initial content of the new instance is equivalent in both type and value to value before the forward.

    Requires:

    C++11 compatible compiler.

    Throws:

    std::bad_alloc or any exceptions arising from the move or copy constructor of the contained type.
  6. any & (any & rhs);

    Copies content of rhs into current instance, discarding previous content, so that the new content is equivalent in both type and value to the content of rhs, or empty if rhs.empty().

    Throws:

    std::bad_alloc or any exceptions arising from the copy constructor of the contained type. Assignment satisfies the strong guarantee of exception safety.
  7. any & (any && rhs) ;

    Moves content of rhs into current instance, discarding previous content, so that the new content is equivalent in both type and value to the content of rhs before move, or empty if rhs.empty().

    Requires:

    C++11 compatible compiler.

    Postconditions:

    rhs->empty() is true

    Throws:

    Nothing.
  8. template<typename ValueType> any & ( rhs);

    Forwards rhs, discarding previous content, so that the new content of is equivalent in both type and value to rhs before forward.

    Requires:

    C++11 compatible compiler.

    Throws:

    std::bad_alloc or any exceptions arising from the move or copy constructor of the contained type. Assignment satisfies the strong guarantee of exception safety.
  9. ~();

    Releases any and all resources used in management of instance.

    Throws:

    Nothing.

any public member functions

  1. any & (any & rhs) ;

    Exchange of the contents of *this and rhs.

    Returns:

    *this

    Throws:

    Nothing.
  2.  () ;

    Returns:

    true if instance is empty, otherwise false.

    Throws:

    Nothing.
  3.  () ;

    Postconditions:

    this->empty() is true

  4.  () ;

    Useful for querying against types known either at compile time or only at runtime.

    Returns:

    the typeid of the contained value if instance is non-empty, otherwise typeid(void).


PrevUpHomeNext