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

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Reference

ValueType requirements
Header <boost/any.hpp>
Header <boost/any/bad_any_cast.hpp>
Header <boost/any/basic_any.hpp>

ValueType requirements

Values are strongly informational objects for which identity is not significant, i.e. the focus is principally on their state content and any behavior organized around that. Another distinguishing feature of values is their granularity: normally fine-grained objects representing simple concepts in the system such as quantities.

As the emphasis of a value lies in its state not its identity, values can be copied and typically assigned one to another, requiring the explicit or implicit definition of a public copy constructor and public assignment operator. Values typically live within other scopes, i.e. within objects or blocks, rather than on the heap. Values are therefore normally passed around and manipulated directly as variables or through references, but not as pointers that emphasize identity and indirection.

The specific requirements on value types to be used in an boost::any and boost::anys::basic_any are:

  • A ValueType is CopyConstructible [20.1.3].
  • The destructor for a ValueType upholds the no-throw exception-safety guarantee.

Header <boost/any.hpp>

namespace boost {
  class any;
  void swap(any &, any &);
  template<typename T> T any_cast(any &);
  template<typename T> T any_cast(any &&);
  template<typename T> T any_cast(const any &);
  template<typename ValueType> const ValueType * any_cast(const any *);
  template<typename ValueType> ValueType * any_cast(any *);
}
namespace boost {
  class bad_any_cast;
}
namespace boost {
  namespace anys {
    template<std::size_t OptimizeForSize, std::size_t OptimizeForAlignment> 
      class basic_any;
    void swap(basic_any &, basic_any &);
    template<typename T> T any_cast(basic_any &);
    template<typename T> T any_cast(basic_any &&);
    template<typename T> T any_cast(const basic_any &);
    template<typename ValueType> const ValueType * any_cast(const basic_any *);
    template<typename ValueType> ValueType * any_cast(basic_any *);
  }
}

PrevUpHomeNext