• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Assign library
2 //
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)
7 //
8 // For more information, see http://www.boost.org/libs/assign/
9 //
10 
11 #ifndef BOOST_ASSIGN_PTR_CONTAINER_PTR_MAP_INSERTER_HPP
12 #define BOOST_ASSIGN_PTR_CONTAINER_PTR_MAP_INSERTER_HPP
13 
14 #if defined(_MSC_VER)
15 # pragma once
16 #endif
17 
18 #include <boost/assign/list_inserter.hpp>
19 #include <boost/type_traits/remove_reference.hpp>
20 #include <boost/type_traits/remove_pointer.hpp>
21 #include <boost/move/utility.hpp>
22 
23 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
24 
25 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
26 #include <boost/preprocessor/repetition/enum_params.hpp>
27 #include <boost/preprocessor/iteration/local.hpp>
28 
29 #endif
30 
31 namespace boost
32 {
33 
34 namespace assign
35 {
36     template< class PtrMap, class Obj >
37     class ptr_map_inserter
38     {
39         typedef BOOST_DEDUCED_TYPENAME
40                 remove_pointer< BOOST_DEDUCED_TYPENAME
41                        remove_reference<Obj>::type >::type
42            obj_type;
43         typedef BOOST_DEDUCED_TYPENAME PtrMap::key_type
44            key_type;
45 
46     public:
47 
ptr_map_inserter(PtrMap & m)48         ptr_map_inserter( PtrMap& m ) : m_( m )
49         {}
50 
51 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
52 
53         template< class Key >
operator ()(const Key & t)54         ptr_map_inserter& operator()( const Key& t )
55         {
56             key_type k(t);
57             m_.insert( k, new obj_type );
58             return *this;
59         }
60 
61 #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value
62 #define BOOST_ASSIGN_MAX_PARAMS 6
63 #endif
64 #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
65 #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T)
66 #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t)
67 #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t)
68 
69 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
70 #define BOOST_PP_LOCAL_MACRO(n) \
71     template< class T, BOOST_ASSIGN_PARAMS1(n) > \
72     ptr_map_inserter& operator()( const T& t, BOOST_ASSIGN_PARAMS2(n) ) \
73     { \
74         key_type k(t); \
75         m_.insert( k, new obj_type( BOOST_ASSIGN_PARAMS3(n) ) ); \
76         return *this; \
77     } \
78     /**/
79 
80 #include BOOST_PP_LOCAL_ITERATE()
81 
82 #else
83     template< class Key, class... Ts >
operator ()(Key && k,Ts &&...ts)84     ptr_map_inserter& operator()(Key&& k, Ts&&... ts)
85     {
86         key_type key(boost::forward<Key>(k));
87         m_.insert(key, new obj_type(boost::forward<Ts>(ts)...));
88         return *this;
89     }
90 
91 #endif
92     private:
93 
94         ptr_map_inserter& operator=( const ptr_map_inserter& );
95         PtrMap& m_;
96     };
97 
98     template< class PtrMap >
99     inline ptr_map_inserter< PtrMap, typename PtrMap::mapped_reference >
ptr_map_insert(PtrMap & m)100     ptr_map_insert( PtrMap& m )
101     {
102         return ptr_map_inserter< PtrMap, typename PtrMap::mapped_reference >( m );
103     }
104 
105 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
106 
107     template< class T, class PtrMap >
108     inline ptr_map_inserter< PtrMap, T >
ptr_map_insert(PtrMap & m)109     ptr_map_insert( PtrMap& m )
110     {
111         return ptr_map_inserter< PtrMap, T >( m );
112     }
113 
114 #endif
115 
116 } // namespace 'assign'
117 } // namespace 'boost'
118 
119 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
120 
121 #undef BOOST_ASSIGN_PARAMS1
122 #undef BOOST_ASSIGN_PARAMS2
123 #undef BOOST_ASSIGN_PARAMS3
124 #undef BOOST_ASSIGN_MAX_PARAMETERS
125 
126 #endif
127 
128 #endif
129