1 // Boost.Assign library
3 // Copyright Thorsten Ottosen 2006. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org/libs/assign/
11 #ifndef BOOST_ASSIGN_PTR_CONTAINER_PTR_MAP_INSERTER_HPP
12 #define BOOST_ASSIGN_PTR_CONTAINER_PTR_MAP_INSERTER_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
18 #include <boost/assign/list_inserter.hpp>
19 #include <boost/type_traits/remove_reference.hpp>
20 #include <boost/type_traits/remove_pointer.hpp>
27 template< class PtrMap, class Obj >
28 class ptr_map_inserter
30 typedef BOOST_DEDUCED_TYPENAME
31 remove_pointer< BOOST_DEDUCED_TYPENAME
32 remove_reference<Obj>::type >::type
34 typedef BOOST_DEDUCED_TYPENAME PtrMap::key_type
39 ptr_map_inserter( PtrMap& m ) : m_( m )
43 ptr_map_inserter& operator()( const Key& t )
46 m_.insert( k, new obj_type );
50 #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value
51 #define BOOST_ASSIGN_MAX_PARAMS 6
53 #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
54 #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T)
55 #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t)
56 #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t)
58 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
59 #define BOOST_PP_LOCAL_MACRO(n) \
60 template< class T, BOOST_ASSIGN_PARAMS1(n) > \
61 ptr_map_inserter& operator()( const T& t, BOOST_ASSIGN_PARAMS2(n) ) \
64 m_.insert( k, new obj_type( BOOST_ASSIGN_PARAMS3(n) ) ); \
69 #include BOOST_PP_LOCAL_ITERATE()
73 ptr_map_inserter& operator=( const ptr_map_inserter& );
77 template< class PtrMap >
78 inline ptr_map_inserter< PtrMap, typename PtrMap::mapped_reference >
79 ptr_map_insert( PtrMap& m )
81 return ptr_map_inserter< PtrMap, typename PtrMap::mapped_reference >( m );
84 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
86 template< class T, class PtrMap >
87 inline ptr_map_inserter< PtrMap, T >
88 ptr_map_insert( PtrMap& m )
90 return ptr_map_inserter< PtrMap, T >( m );
95 } // namespace 'assign'
96 } // namespace 'boost'
98 #undef BOOST_ASSIGN_PARAMS1
99 #undef BOOST_ASSIGN_PARAMS2
100 #undef BOOST_ASSIGN_PARAMS3
101 #undef BOOST_ASSIGN_MAX_PARAMETERS