]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/assign/ptr_list_of.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / assign / ptr_list_of.hpp
CommitLineData
7c673cae
FG
1// Boost.Assign library
2//
3// Copyright Thorsten Ottosen 2003-2005. 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
12#ifndef BOOST_ASSIGN_PTR_LIST_OF_HPP
13#define BOOST_ASSIGN_PTR_LIST_OF_HPP
14
15#if defined(_MSC_VER)
16# pragma once
17#endif
18
19#include <boost/assign/list_of.hpp>
20#include <boost/type_traits/remove_const.hpp>
21#include <boost/type_traits/remove_reference.hpp>
22#include <boost/type_traits/is_reference.hpp>
23#include <boost/static_assert.hpp>
24#include <boost/type_traits/detail/yes_no_type.hpp>
25#include <boost/type_traits/decay.hpp>
26#include <boost/type_traits/is_array.hpp>
27#include <boost/mpl/if.hpp>
28#include <boost/ptr_container/ptr_vector.hpp>
29
30#include <boost/preprocessor/repetition/enum_binary_params.hpp>
31#include <boost/preprocessor/repetition/enum_params.hpp>
32#include <boost/preprocessor/iteration/local.hpp>
33
34namespace boost
35{
36
37namespace assign_detail
38{
39 /////////////////////////////////////////////////////////////////////////
40 // Part 1: flexible and efficient interface
41 /////////////////////////////////////////////////////////////////////////
42
43 template< class T >
44 class generic_ptr_list :
45 public converter< generic_ptr_list<T>,
46 BOOST_DEDUCED_TYPENAME boost::ptr_vector<T>::iterator >
47 {
48 protected:
49 typedef boost::ptr_vector<T> impl_type;
11fdf7f2
TL
50#if defined(BOOST_NO_AUTO_PTR)
51 typedef std::unique_ptr<impl_type> release_type;
52#else
7c673cae 53 typedef std::auto_ptr<impl_type> release_type;
11fdf7f2 54#endif
7c673cae
FG
55 mutable impl_type values_;
56
57 public:
58 typedef BOOST_DEDUCED_TYPENAME impl_type::iterator iterator;
59 typedef iterator const_iterator;
60 typedef BOOST_DEDUCED_TYPENAME impl_type::value_type value_type;
61 typedef BOOST_DEDUCED_TYPENAME impl_type::size_type size_type;
62 typedef BOOST_DEDUCED_TYPENAME impl_type::difference_type difference_type;
63 public:
64 generic_ptr_list() : values_( 32u )
65 { }
66
67 generic_ptr_list( release_type r ) : values_(r)
68 { }
69
70 release_type release()
71 {
72 return values_.release();
73 }
74
75 public:
76 iterator begin() const { return values_.begin(); }
77 iterator end() const { return values_.end(); }
78 bool empty() const { return values_.empty(); }
79 size_type size() const { return values_.size(); }
80
81 public:
82
83 operator impl_type() const
84 {
85 return values_;
86 }
87
88 template< template<class,class,class> class Seq, class U,
89 class CA, class A >
90 operator Seq<U,CA,A>() const
91 {
92 Seq<U,CA,A> result;
93 result.transfer( result.end(), values_ );
94 BOOST_ASSERT( empty() );
95 return result;
96 }
97
98 template< class PtrContainer >
11fdf7f2
TL
99#if defined(BOOST_NO_AUTO_PTR)
100 std::unique_ptr<PtrContainer>
101#else
102 std::auto_ptr<PtrContainer>
103#endif
104 convert( const PtrContainer* c ) const
7c673cae 105 {
11fdf7f2
TL
106#if defined(BOOST_NO_AUTO_PTR)
107 std::unique_ptr<PtrContainer> res( new PtrContainer() );
108#else
7c673cae 109 std::auto_ptr<PtrContainer> res( new PtrContainer() );
11fdf7f2 110#endif
7c673cae
FG
111 while( !empty() )
112 res->insert( res->end(),
113 values_.pop_back().release() );
114 return res;
115 }
116
117 template< class PtrContainer >
11fdf7f2
TL
118#if defined(BOOST_NO_AUTO_PTR)
119 std::unique_ptr<PtrContainer>
120#else
121 std::auto_ptr<PtrContainer>
122#endif
123 to_container( const PtrContainer& c ) const
7c673cae
FG
124 {
125 return convert( &c );
126 }
127
128 protected:
129 void push_back( T* r ) { values_.push_back( r ); }
130
131 public:
132 generic_ptr_list& operator()()
133 {
134 this->push_back( new T() );
135 return *this;
136 }
137
138 template< class U >
139 generic_ptr_list& operator()( const U& u )
140 {
141 this->push_back( new T(u) );
142 return *this;
143 }
144
145
146#ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value
147#define BOOST_ASSIGN_MAX_PARAMS 5
148#endif
149#define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
150#define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class U)
151#define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, U, const& u)
152#define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, u)
153
154#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
155#define BOOST_PP_LOCAL_MACRO(n) \
156 template< class U, BOOST_ASSIGN_PARAMS1(n) > \
157 generic_ptr_list& operator()(U const& u, BOOST_ASSIGN_PARAMS2(n) ) \
158 { \
159 this->push_back( new T(u, BOOST_ASSIGN_PARAMS3(n))); \
160 return *this; \
161 } \
162 /**/
163
164#include BOOST_PP_LOCAL_ITERATE()
165
166 }; // class 'generic_ptr_list'
167
168} // namespace 'assign_detail'
169
170namespace assign
171{
172 template< class T >
173 inline assign_detail::generic_ptr_list<T>
174 ptr_list_of()
175 {
176 return assign_detail::generic_ptr_list<T>()();
177 }
178
179 template< class T, class U >
180 inline assign_detail::generic_ptr_list<T>
181 ptr_list_of( const U& t )
182 {
183 return assign_detail::generic_ptr_list<T>()( t );
184 }
185
186
187#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
188#define BOOST_PP_LOCAL_MACRO(n) \
189 template< class T, class U, BOOST_ASSIGN_PARAMS1(n) > \
190 inline assign_detail::generic_ptr_list<T> \
191 ptr_list_of(U const& u, BOOST_ASSIGN_PARAMS2(n) ) \
192 { \
193 return assign_detail::generic_ptr_list<T>()(u, BOOST_ASSIGN_PARAMS3(n)); \
194 } \
195 /**/
196
197#include BOOST_PP_LOCAL_ITERATE()
198
199
200} // namespace 'assign'
201} // namespace 'boost'
202
203
204#undef BOOST_ASSIGN_PARAMS1
205#undef BOOST_ASSIGN_PARAMS2
206#undef BOOST_ASSIGN_PARAMS3
207#undef BOOST_ASSIGN_MAX_PARAMETERS
208
209#endif