Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template basic_type_map

boost::extensions::basic_type_map — A collection of types.

Synopsis

template<typename TypeInfo> 
class basic_type_map {
public:

  // public member functions
   BOOST_STATIC_ASSERT(has_nothrow_assign< TypeInfo >::value) ;
   BOOST_STATIC_ASSERT(has_nothrow_copy_constructor< TypeInfo >::value) ;
  template<typename Type> Type & get() ;
};

Description

The `type_map` class is used for holding an arbitrary collection of types - no more than one of each type. In general, standard usage is as follows:

 type_map types;
 // This will add an integer to the type_map, or retrieve
 // one if it already exists.
 int& first_int(types.get());
 first_int = 5;
 // This will make second_int point to the same value
 // as first_int.
 int& second_int(types.get());
 second_int = 10;
 // Now first_int is 10.
 // It is also possible to use arbitrary types in the map,
 // as long as they are default constructible.
 std::set<std::string>& my_string(types.get());

basic_type_map public member functions

  1.  BOOST_STATIC_ASSERT(has_nothrow_assign< TypeInfo >::value) ;
  2.  BOOST_STATIC_ASSERT(has_nothrow_copy_constructor< TypeInfo >::value) ;
  3. template<typename Type> Type & get() ;

    This is the only method users should ever need to use. By calling it with a template argument `Type`, a reference to the single object of that type will be returned, after being created if necessary. It is possible to omit the template parameter if it is clear from context:

     type_map types;
     int& my_int(types.get());
    


PrevUpHomeNext