]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/assign/ptr_map_inserter.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / assign / ptr_map_inserter.hpp
CommitLineData
7c673cae
FG
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>
92f5a8d4
TL
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
7c673cae
FG
30
31namespace boost
32{
33
34namespace 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
48 ptr_map_inserter( PtrMap& m ) : m_( m )
49 {}
92f5a8d4
TL
50
51#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
52
7c673cae
FG
53 template< class Key >
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
92f5a8d4
TL
82#else
83 template< class Key, class... 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
7c673cae
FG
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 >
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 >
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
92f5a8d4
TL
119#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
120
7c673cae
FG
121#undef BOOST_ASSIGN_PARAMS1
122#undef BOOST_ASSIGN_PARAMS2
123#undef BOOST_ASSIGN_PARAMS3
124#undef BOOST_ASSIGN_MAX_PARAMETERS
125
126#endif
92f5a8d4
TL
127
128#endif