Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:13

0001 // Boost.Assign library
0002 //
0003 //  Copyright Thorsten Ottosen 2003-2005. Use, modification and
0004 //  distribution is subject to the Boost Software License, Version
0005 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0006 //  http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // For more information, see http://www.boost.org/libs/assign/
0009 //
0010 
0011 
0012 #ifndef BOOST_ASSIGN_PTR_LIST_OF_HPP
0013 #define BOOST_ASSIGN_PTR_LIST_OF_HPP
0014 
0015 #if defined(_MSC_VER)
0016 # pragma once
0017 #endif
0018 
0019 #include <boost/assign/list_of.hpp>
0020 #include <boost/type_traits/remove_const.hpp>
0021 #include <boost/type_traits/remove_reference.hpp>
0022 #include <boost/type_traits/is_reference.hpp>
0023 #include <boost/static_assert.hpp>
0024 #include <boost/type_traits/detail/yes_no_type.hpp>
0025 #include <boost/type_traits/decay.hpp>
0026 #include <boost/type_traits/is_array.hpp>
0027 #include <boost/ptr_container/ptr_vector.hpp>
0028 #include <boost/move/utility.hpp>
0029 
0030 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0031 
0032 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
0033 #include <boost/preprocessor/repetition/enum_params.hpp>
0034 #include <boost/preprocessor/iteration/local.hpp>
0035 
0036 #endif
0037 
0038 namespace boost
0039 {
0040 
0041 namespace assign_detail
0042 {
0043     /////////////////////////////////////////////////////////////////////////
0044     // Part 1: flexible and efficient interface
0045     /////////////////////////////////////////////////////////////////////////
0046 
0047     template< class T >
0048     class generic_ptr_list :
0049         public converter< generic_ptr_list<T>,
0050                           BOOST_DEDUCED_TYPENAME boost::ptr_vector<T>::iterator >
0051     {
0052     protected:
0053         typedef boost::ptr_vector<T>       impl_type;
0054 #if defined(BOOST_NO_AUTO_PTR)
0055         typedef std::unique_ptr<impl_type> release_type;
0056 #else
0057         typedef std::auto_ptr<impl_type>   release_type;
0058 #endif  
0059         mutable impl_type                  values_;
0060 
0061     public:
0062         typedef BOOST_DEDUCED_TYPENAME impl_type::iterator         iterator;
0063         typedef iterator                                           const_iterator;
0064         typedef BOOST_DEDUCED_TYPENAME impl_type::value_type       value_type;
0065         typedef BOOST_DEDUCED_TYPENAME impl_type::size_type        size_type;
0066         typedef BOOST_DEDUCED_TYPENAME impl_type::difference_type  difference_type;
0067     public:
0068         generic_ptr_list() : values_( 32u )
0069         { }
0070 
0071         generic_ptr_list( release_type r ) : values_(r)
0072         { }
0073 
0074         release_type release()
0075         {
0076             return values_.release();
0077         }
0078 
0079     public:
0080         iterator begin() const       { return values_.begin(); }
0081         iterator end() const         { return values_.end(); }
0082         bool empty() const           { return values_.empty(); }
0083         size_type size() const       { return values_.size(); }
0084 
0085     public:
0086 
0087         operator impl_type() const
0088         {
0089             return values_;
0090         }
0091 
0092         template< template<class,class,class> class Seq, class U,
0093                   class CA, class A >
0094         operator Seq<U,CA,A>() const
0095         {
0096             Seq<U,CA,A> result;
0097             result.transfer( result.end(), values_ );
0098             BOOST_ASSERT( empty() );
0099             return result;
0100         }
0101 
0102         template< class PtrContainer >
0103 #if defined(BOOST_NO_AUTO_PTR)
0104         std::unique_ptr<PtrContainer>
0105 #else
0106         std::auto_ptr<PtrContainer>
0107 #endif  
0108         convert( const PtrContainer* c ) const
0109         {
0110 #if defined(BOOST_NO_AUTO_PTR)
0111             std::unique_ptr<PtrContainer> res( new PtrContainer() );
0112 #else
0113             std::auto_ptr<PtrContainer> res( new PtrContainer() );
0114 #endif  
0115             while( !empty() )
0116                 res->insert( res->end(),
0117                              values_.pop_back().release() );
0118             return res;
0119         }
0120 
0121         template< class PtrContainer >
0122 #if defined(BOOST_NO_AUTO_PTR)
0123         std::unique_ptr<PtrContainer>
0124 #else
0125         std::auto_ptr<PtrContainer>
0126 #endif  
0127         to_container( const PtrContainer& c ) const
0128         {
0129             return convert( &c );
0130         }
0131 
0132     protected:
0133         void push_back( T* r ) { values_.push_back( r ); }
0134 
0135     public:
0136 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0137 
0138         generic_ptr_list& operator()()
0139         {
0140             this->push_back( new T() );
0141             return *this;
0142         }
0143 
0144         template< class U >
0145         generic_ptr_list& operator()( const U& u )
0146         {
0147             this->push_back( new T(u) );
0148             return *this;
0149         }
0150 
0151 
0152 #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value
0153 #define BOOST_ASSIGN_MAX_PARAMS 5
0154 #endif
0155 #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
0156 #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class U)
0157 #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, U, const& u)
0158 #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, u)
0159 
0160 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
0161 #define BOOST_PP_LOCAL_MACRO(n) \
0162     template< class U, BOOST_ASSIGN_PARAMS1(n) > \
0163     generic_ptr_list& operator()(U const& u, BOOST_ASSIGN_PARAMS2(n) ) \
0164     { \
0165         this->push_back( new T(u, BOOST_ASSIGN_PARAMS3(n))); \
0166         return *this; \
0167     } \
0168     /**/
0169 
0170 #include BOOST_PP_LOCAL_ITERATE()
0171 
0172 #else
0173         template< class... Us >
0174         generic_ptr_list& operator()(Us&&... us)
0175         {
0176             this->push_back(new T(boost::forward<Us>(us)...));
0177             return *this;
0178         }
0179 #endif
0180 
0181 
0182 
0183     }; // class 'generic_ptr_list'
0184 
0185 } // namespace 'assign_detail'
0186 
0187 namespace assign
0188 {
0189 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0190 
0191     template< class T >
0192     inline assign_detail::generic_ptr_list<T>
0193     ptr_list_of()
0194     {
0195         assign_detail::generic_ptr_list<T> gpl;
0196         gpl();
0197         return gpl;
0198     }
0199 
0200     template< class T, class U >
0201     inline assign_detail::generic_ptr_list<T>
0202     ptr_list_of( const U& t )
0203     {
0204         assign_detail::generic_ptr_list<T> gpl;
0205         gpl( t );
0206         return gpl;
0207     }
0208 
0209 
0210 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
0211 #define BOOST_PP_LOCAL_MACRO(n) \
0212     template< class T, class U, BOOST_ASSIGN_PARAMS1(n) > \
0213     inline assign_detail::generic_ptr_list<T> \
0214     ptr_list_of(U const& u, BOOST_ASSIGN_PARAMS2(n) ) \
0215     { \
0216         return assign_detail::generic_ptr_list<T>()(u, BOOST_ASSIGN_PARAMS3(n)); \
0217     } \
0218     /**/
0219 
0220 #include BOOST_PP_LOCAL_ITERATE()
0221 
0222 #else
0223     template< class T, class... Us >
0224     inline assign_detail::generic_ptr_list<T>
0225     ptr_list_of(Us&&... us)
0226     {
0227         assign_detail::generic_ptr_list<T> gpl;
0228         gpl(boost::forward<Us>(us)...);
0229         return gpl;
0230     }
0231 
0232 #endif
0233 
0234 } // namespace 'assign'
0235 } // namespace 'boost'
0236 
0237 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0238 
0239 #undef BOOST_ASSIGN_PARAMS1
0240 #undef BOOST_ASSIGN_PARAMS2
0241 #undef BOOST_ASSIGN_PARAMS3
0242 #undef BOOST_ASSIGN_MAX_PARAMETERS
0243 
0244 #endif
0245 
0246 #endif