File indexing completed on 2025-01-18 09:29:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASSIGN_PTR_CONTAINER_PTR_MAP_INSERTER_HPP
0012 #define BOOST_ASSIGN_PTR_CONTAINER_PTR_MAP_INSERTER_HPP
0013
0014 #if defined(_MSC_VER)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/assign/list_inserter.hpp>
0019 #include <boost/type_traits/remove_reference.hpp>
0020 #include <boost/type_traits/remove_pointer.hpp>
0021 #include <boost/move/utility.hpp>
0022
0023 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0024
0025 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
0026 #include <boost/preprocessor/repetition/enum_params.hpp>
0027 #include <boost/preprocessor/iteration/local.hpp>
0028
0029 #endif
0030
0031 namespace boost
0032 {
0033
0034 namespace assign
0035 {
0036 template< class PtrMap, class Obj >
0037 class ptr_map_inserter
0038 {
0039 typedef BOOST_DEDUCED_TYPENAME
0040 remove_pointer< BOOST_DEDUCED_TYPENAME
0041 remove_reference<Obj>::type >::type
0042 obj_type;
0043 typedef BOOST_DEDUCED_TYPENAME PtrMap::key_type
0044 key_type;
0045
0046 public:
0047
0048 ptr_map_inserter( PtrMap& m ) : m_( m )
0049 {}
0050
0051 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0052
0053 template< class Key >
0054 ptr_map_inserter& operator()( const Key& t )
0055 {
0056 key_type k(t);
0057 m_.insert( k, new obj_type );
0058 return *this;
0059 }
0060
0061 #ifndef BOOST_ASSIGN_MAX_PARAMS
0062 #define BOOST_ASSIGN_MAX_PARAMS 6
0063 #endif
0064 #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
0065 #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T)
0066 #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t)
0067 #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t)
0068
0069 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
0070 #define BOOST_PP_LOCAL_MACRO(n) \
0071 template< class T, BOOST_ASSIGN_PARAMS1(n) > \
0072 ptr_map_inserter& operator()( const T& t, BOOST_ASSIGN_PARAMS2(n) ) \
0073 { \
0074 key_type k(t); \
0075 m_.insert( k, new obj_type( BOOST_ASSIGN_PARAMS3(n) ) ); \
0076 return *this; \
0077 } \
0078
0079
0080 #include BOOST_PP_LOCAL_ITERATE()
0081
0082 #else
0083 template< class Key, class... Ts >
0084 ptr_map_inserter& operator()(Key&& k, Ts&&... ts)
0085 {
0086 key_type key(boost::forward<Key>(k));
0087 m_.insert(key, new obj_type(boost::forward<Ts>(ts)...));
0088 return *this;
0089 }
0090
0091 #endif
0092 private:
0093
0094 ptr_map_inserter& operator=( const ptr_map_inserter& );
0095 PtrMap& m_;
0096 };
0097
0098 template< class PtrMap >
0099 inline ptr_map_inserter< PtrMap, typename PtrMap::mapped_reference >
0100 ptr_map_insert( PtrMap& m )
0101 {
0102 return ptr_map_inserter< PtrMap, typename PtrMap::mapped_reference >( m );
0103 }
0104
0105 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
0106
0107 template< class T, class PtrMap >
0108 inline ptr_map_inserter< PtrMap, T >
0109 ptr_map_insert( PtrMap& m )
0110 {
0111 return ptr_map_inserter< PtrMap, T >( m );
0112 }
0113
0114 #endif
0115
0116 }
0117 }
0118
0119 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0120
0121 #undef BOOST_ASSIGN_PARAMS1
0122 #undef BOOST_ASSIGN_PARAMS2
0123 #undef BOOST_ASSIGN_PARAMS3
0124 #undef BOOST_ASSIGN_MAX_PARAMETERS
0125
0126 #endif
0127
0128 #endif