1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/ptr_container/ptr_set_adapter.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,513 @@
1.4 +//
1.5 +// Boost.Pointer Container
1.6 +//
1.7 +// Copyright Thorsten Ottosen 2003-2005. Use, modification and
1.8 +// distribution is subject to the Boost Software License, Version
1.9 +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.10 +// http://www.boost.org/LICENSE_1_0.txt)
1.11 +//
1.12 +// For more information, see http://www.boost.org/libs/ptr_container/
1.13 +//
1.14 +
1.15 +#ifndef BOOST_PTR_CONTAINER_PTR_SET_ADAPTER_HPP
1.16 +#define BOOST_PTR_CONTAINER_PTR_SET_ADAPTER_HPP
1.17 +
1.18 +#if defined(_MSC_VER) && (_MSC_VER >= 1200)
1.19 +# pragma once
1.20 +#endif
1.21 +
1.22 +#include <boost/ptr_container/detail/associative_ptr_container.hpp>
1.23 +#include <boost/ptr_container/detail/void_ptr_iterator.hpp>
1.24 +#include <boost/range/iterator_range.hpp>
1.25 +
1.26 +namespace boost
1.27 +{
1.28 +namespace ptr_container_detail
1.29 +{
1.30 + template
1.31 + <
1.32 + class Key,
1.33 + class VoidPtrSet
1.34 + >
1.35 + struct set_config
1.36 + {
1.37 + typedef VoidPtrSet
1.38 + void_container_type;
1.39 +
1.40 + typedef BOOST_DEDUCED_TYPENAME VoidPtrSet::allocator_type
1.41 + allocator_type;
1.42 +
1.43 + typedef Key value_type;
1.44 +
1.45 + typedef value_type
1.46 + key_type;
1.47 +
1.48 + typedef BOOST_DEDUCED_TYPENAME VoidPtrSet::value_compare
1.49 + value_compare;
1.50 +
1.51 + typedef value_compare
1.52 + key_compare;
1.53 +
1.54 + typedef void_ptr_iterator<
1.55 + BOOST_DEDUCED_TYPENAME VoidPtrSet::iterator, Key >
1.56 + iterator;
1.57 +
1.58 + typedef void_ptr_iterator<
1.59 + BOOST_DEDUCED_TYPENAME VoidPtrSet::const_iterator, const Key >
1.60 + const_iterator;
1.61 +
1.62 + template< class Iter >
1.63 + static Key* get_pointer( Iter i )
1.64 + {
1.65 + return static_cast<Key*>( *i.base() );
1.66 + }
1.67 +
1.68 + template< class Iter >
1.69 + static const Key* get_const_pointer( Iter i )
1.70 + {
1.71 + return static_cast<const Key*>( *i.base() );
1.72 + }
1.73 +
1.74 + BOOST_STATIC_CONSTANT(bool, allow_null = false );
1.75 + };
1.76 +
1.77 +
1.78 +
1.79 + template
1.80 + <
1.81 + class Key,
1.82 + class VoidPtrSet,
1.83 + class CloneAllocator = heap_clone_allocator
1.84 + >
1.85 + class ptr_set_adapter_base
1.86 + : public ptr_container_detail::associative_ptr_container< set_config<Key,VoidPtrSet>,
1.87 + CloneAllocator >
1.88 + {
1.89 + typedef ptr_container_detail::associative_ptr_container< set_config<Key,VoidPtrSet>,
1.90 + CloneAllocator >
1.91 + base_type;
1.92 + public:
1.93 + typedef BOOST_DEDUCED_TYPENAME base_type::iterator
1.94 + iterator;
1.95 + typedef BOOST_DEDUCED_TYPENAME base_type::const_iterator
1.96 + const_iterator;
1.97 + typedef Key key_type;
1.98 + typedef BOOST_DEDUCED_TYPENAME base_type::size_type
1.99 + size_type;
1.100 +
1.101 + private:
1.102 + ptr_set_adapter_base()
1.103 + : base_type( BOOST_DEDUCED_TYPENAME VoidPtrSet::key_compare(),
1.104 + BOOST_DEDUCED_TYPENAME VoidPtrSet::allocator_type() )
1.105 + { }
1.106 +
1.107 + public:
1.108 +
1.109 + template< class Compare, class Allocator >
1.110 + ptr_set_adapter_base( const Compare& comp,
1.111 + const Allocator& a )
1.112 + : base_type( comp, a )
1.113 + { }
1.114 +
1.115 + template< class InputIterator, class Compare, class Allocator >
1.116 + ptr_set_adapter_base( InputIterator first, InputIterator last,
1.117 + const Compare& comp,
1.118 + const Allocator& a )
1.119 + : base_type( first, last, comp, a )
1.120 + { }
1.121 +
1.122 + template< class PtrContainer >
1.123 + ptr_set_adapter_base( std::auto_ptr<PtrContainer> clone )
1.124 + : base_type( clone )
1.125 + { }
1.126 +
1.127 + template< typename PtrContainer >
1.128 + void operator=( std::auto_ptr<PtrContainer> clone )
1.129 + {
1.130 + base_type::operator=( clone );
1.131 + }
1.132 +
1.133 + iterator find( const key_type& x )
1.134 + {
1.135 + return iterator( this->c_private().
1.136 + find( const_cast<key_type*>(&x) ) );
1.137 + }
1.138 +
1.139 + const_iterator find( const key_type& x ) const
1.140 + {
1.141 + return const_iterator( this->c_private().
1.142 + find( const_cast<key_type*>(&x) ) );
1.143 + }
1.144 +
1.145 + size_type count( const key_type& x ) const
1.146 + {
1.147 + return this->c_private().count( const_cast<key_type*>(&x) );
1.148 + }
1.149 +
1.150 + iterator lower_bound( const key_type& x )
1.151 + {
1.152 + return iterator( this->c_private().
1.153 + lower_bound( const_cast<key_type*>(&x) ) );
1.154 + }
1.155 +
1.156 + const_iterator lower_bound( const key_type& x ) const
1.157 + {
1.158 + return const_iterator( this->c_private().
1.159 + lower_bound( const_cast<key_type*>(&x) ) );
1.160 + }
1.161 +
1.162 + iterator upper_bound( const key_type& x )
1.163 + {
1.164 + return iterator( this->c_private().
1.165 + upper_bound( const_cast<key_type*>(&x) ) );
1.166 + }
1.167 +
1.168 + const_iterator upper_bound( const key_type& x ) const
1.169 + {
1.170 + return const_iterator( this->c_private().
1.171 + upper_bound( const_cast<key_type*>(&x) ) );
1.172 + }
1.173 +
1.174 + iterator_range<iterator> equal_range( const key_type& x )
1.175 + {
1.176 + std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,
1.177 + BOOST_DEDUCED_TYPENAME base_type::ptr_iterator>
1.178 + p = this->c_private().
1.179 + equal_range( const_cast<key_type*>(&x) );
1.180 + return make_iterator_range( iterator( p.first ),
1.181 + iterator( p.second ) );
1.182 + }
1.183 +
1.184 + iterator_range<const_iterator> equal_range( const key_type& x ) const
1.185 + {
1.186 + std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_const_iterator,
1.187 + BOOST_DEDUCED_TYPENAME base_type::ptr_const_iterator>
1.188 + p = this->c_private().
1.189 + equal_range( const_cast<key_type*>(&x) );
1.190 + return make_iterator_range( const_iterator( p.first ),
1.191 + const_iterator( p.second ) );
1.192 + }
1.193 +
1.194 + };
1.195 +
1.196 +} // ptr_container_detail
1.197 +
1.198 + /////////////////////////////////////////////////////////////////////////
1.199 + // ptr_set_adapter
1.200 + /////////////////////////////////////////////////////////////////////////
1.201 +
1.202 + template
1.203 + <
1.204 + class Key,
1.205 + class VoidPtrSet,
1.206 + class CloneAllocator = heap_clone_allocator
1.207 + >
1.208 + class ptr_set_adapter :
1.209 + public ptr_container_detail::ptr_set_adapter_base<Key,VoidPtrSet,CloneAllocator>
1.210 + {
1.211 + typedef ptr_container_detail::ptr_set_adapter_base<Key,VoidPtrSet,CloneAllocator>
1.212 + base_type;
1.213 +
1.214 + public: // typedefs
1.215 +
1.216 + typedef BOOST_DEDUCED_TYPENAME base_type::iterator
1.217 + iterator;
1.218 + typedef BOOST_DEDUCED_TYPENAME base_type::const_iterator
1.219 + const_iterator;
1.220 + typedef BOOST_DEDUCED_TYPENAME base_type::size_type
1.221 + size_type;
1.222 + typedef Key key_type;
1.223 + typedef BOOST_DEDUCED_TYPENAME base_type::auto_type
1.224 + auto_type;
1.225 + typedef BOOST_DEDUCED_TYPENAME VoidPtrSet::key_compare
1.226 + key_compare;
1.227 + typedef BOOST_DEDUCED_TYPENAME VoidPtrSet::allocator_type
1.228 + allocator_type;
1.229 + private:
1.230 +
1.231 + template< typename II >
1.232 + void set_basic_clone_and_insert( II first, II last ) // basic
1.233 + {
1.234 + while( first != last )
1.235 + {
1.236 + if( this->find( *first ) == this->end() )
1.237 + insert( CloneAllocator::allocate_clone( *first ) ); // strong, commit
1.238 + ++first;
1.239 + }
1.240 + }
1.241 +
1.242 + public:
1.243 +
1.244 + explicit ptr_set_adapter( const key_compare& comp = key_compare(),
1.245 + const allocator_type& a = allocator_type() )
1.246 + : base_type( comp, a )
1.247 + {
1.248 + BOOST_ASSERT( this->empty() );
1.249 + }
1.250 +
1.251 + template< class InputIterator, class Compare, class Allocator >
1.252 + ptr_set_adapter( InputIterator first, InputIterator last,
1.253 + const Compare& comp = Compare(),
1.254 + const Allocator a = Allocator() )
1.255 + : base_type( comp, a )
1.256 + {
1.257 + BOOST_ASSERT( this->empty() );
1.258 + set_basic_clone_and_insert( first, last );
1.259 + }
1.260 +
1.261 + template< class T >
1.262 + ptr_set_adapter( std::auto_ptr<T> r ) : base_type( r )
1.263 + { }
1.264 +
1.265 + template< class T >
1.266 + void operator=( std::auto_ptr<T> r )
1.267 + {
1.268 + base_type::operator=( r );
1.269 + }
1.270 +
1.271 + std::pair<iterator,bool> insert( key_type* x ) // strong
1.272 + {
1.273 + this->enforce_null_policy( x, "Null pointer in 'ptr_set::insert()'" );
1.274 +
1.275 + auto_type ptr( x );
1.276 + std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool>
1.277 + res = this->c_private().insert( x );
1.278 + if( res.second )
1.279 + ptr.release();
1.280 + return std::make_pair( iterator( res.first ), res.second );
1.281 + }
1.282 +
1.283 + template< class U >
1.284 + std::pair<iterator,bool> insert( std::auto_ptr<U> x )
1.285 + {
1.286 + return insert( x.release() );
1.287 + }
1.288 +
1.289 +
1.290 + iterator insert( iterator where, key_type* x ) // strong
1.291 + {
1.292 + this->enforce_null_policy( x, "Null pointer in 'ptr_set::insert()'" );
1.293 +
1.294 + auto_type ptr( x );
1.295 + BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
1.296 + res = this->c_private().insert( where.base(), x );
1.297 + if( *res == x )
1.298 + ptr.release();
1.299 + return iterator( res);
1.300 + }
1.301 +
1.302 + template< class U >
1.303 + iterator insert( iterator where, std::auto_ptr<U> x )
1.304 + {
1.305 + return insert( where, x.release() );
1.306 + }
1.307 +
1.308 + template< typename InputIterator >
1.309 + void insert( InputIterator first, InputIterator last ) // basic
1.310 + {
1.311 + set_basic_clone_and_insert( first, last );
1.312 + }
1.313 +
1.314 +#if defined(BOOST_NO_SFINAE) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
1.315 +#else
1.316 +
1.317 + template< class Range >
1.318 + BOOST_DEDUCED_TYPENAME
1.319 + boost::disable_if< ptr_container_detail::is_pointer_or_integral<Range> >::type
1.320 + insert( const Range& r )
1.321 + {
1.322 + insert( boost::begin(r), boost::end(r) );
1.323 + }
1.324 +
1.325 +#endif
1.326 +
1.327 + template< class PtrSetAdapter >
1.328 + bool transfer( BOOST_DEDUCED_TYPENAME PtrSetAdapter::iterator object,
1.329 + PtrSetAdapter& from ) // strong
1.330 + {
1.331 + return this->single_transfer( object, from );
1.332 + }
1.333 +
1.334 + template< class PtrSetAdapter >
1.335 + size_type
1.336 + transfer( BOOST_DEDUCED_TYPENAME PtrSetAdapter::iterator first,
1.337 + BOOST_DEDUCED_TYPENAME PtrSetAdapter::iterator last,
1.338 + PtrSetAdapter& from ) // basic
1.339 + {
1.340 + return this->single_transfer( first, last, from );
1.341 + }
1.342 +
1.343 +#if defined(BOOST_NO_SFINAE) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
1.344 +#else
1.345 +
1.346 + template< class PtrSetAdapter, class Range >
1.347 + BOOST_DEDUCED_TYPENAME boost::disable_if< boost::is_same< Range,
1.348 + BOOST_DEDUCED_TYPENAME PtrSetAdapter::iterator >,
1.349 + size_type >::type
1.350 + transfer( const Range& r, PtrSetAdapter& from ) // basic
1.351 + {
1.352 + return transfer( boost::begin(r), boost::end(r), from );
1.353 + }
1.354 +
1.355 +#endif
1.356 +
1.357 + template< class PtrSetAdapter >
1.358 + size_type transfer( PtrSetAdapter& from ) // basic
1.359 + {
1.360 + return transfer( from.begin(), from.end(), from );
1.361 + }
1.362 +
1.363 + };
1.364 +
1.365 + /////////////////////////////////////////////////////////////////////////
1.366 + // ptr_multiset_adapter
1.367 + /////////////////////////////////////////////////////////////////////////
1.368 +
1.369 + template
1.370 + <
1.371 + class Key,
1.372 + class VoidPtrMultiSet,
1.373 + class CloneAllocator = heap_clone_allocator
1.374 + >
1.375 + class ptr_multiset_adapter :
1.376 + public ptr_container_detail::ptr_set_adapter_base<Key,VoidPtrMultiSet,CloneAllocator>
1.377 + {
1.378 + typedef ptr_container_detail::ptr_set_adapter_base<Key,VoidPtrMultiSet,CloneAllocator> base_type;
1.379 +
1.380 + public: // typedefs
1.381 +
1.382 + typedef BOOST_DEDUCED_TYPENAME base_type::iterator
1.383 + iterator;
1.384 + typedef BOOST_DEDUCED_TYPENAME base_type::size_type
1.385 + size_type;
1.386 + typedef Key key_type;
1.387 + typedef BOOST_DEDUCED_TYPENAME base_type::auto_type
1.388 + auto_type;
1.389 + typedef BOOST_DEDUCED_TYPENAME VoidPtrMultiSet::key_compare
1.390 + key_compare;
1.391 + typedef BOOST_DEDUCED_TYPENAME VoidPtrMultiSet::allocator_type
1.392 + allocator_type;
1.393 + private:
1.394 + template< typename II >
1.395 + void set_basic_clone_and_insert( II first, II last ) // basic
1.396 + {
1.397 + while( first != last )
1.398 + {
1.399 + insert( CloneAllocator::allocate_clone( *first ) ); // strong, commit
1.400 + ++first;
1.401 + }
1.402 + }
1.403 +
1.404 + public:
1.405 +
1.406 + explicit ptr_multiset_adapter( const key_compare& comp = key_compare(),
1.407 + const allocator_type& a = allocator_type() )
1.408 + : base_type( comp, a )
1.409 + { }
1.410 +
1.411 + template< class InputIterator >
1.412 + ptr_multiset_adapter( InputIterator first, InputIterator last,
1.413 + const key_compare& comp = key_compare(),
1.414 + const allocator_type& a = allocator_type() )
1.415 + : base_type( comp, a )
1.416 + {
1.417 + set_basic_clone_and_insert( first, last );
1.418 + }
1.419 +
1.420 + template< class T >
1.421 + ptr_multiset_adapter( std::auto_ptr<T> r ) : base_type( r )
1.422 + { }
1.423 +
1.424 + template< class T >
1.425 + void operator=( std::auto_ptr<T> r )
1.426 + {
1.427 + base_type::operator=( r );
1.428 + }
1.429 +
1.430 + iterator insert( iterator before, key_type* x ) // strong
1.431 + {
1.432 + return base_type::insert( before, x );
1.433 + }
1.434 +
1.435 + template< class U >
1.436 + iterator insert( iterator before, std::auto_ptr<U> x )
1.437 + {
1.438 + return insert( before, x.release() );
1.439 + }
1.440 +
1.441 + iterator insert( key_type* x ) // strong
1.442 + {
1.443 + this->enforce_null_policy( x, "Null pointer in 'ptr_multiset::insert()'" );
1.444 +
1.445 + auto_type ptr( x );
1.446 + BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
1.447 + res = this->c_private().insert( x );
1.448 + ptr.release();
1.449 + return iterator( res );
1.450 + }
1.451 +
1.452 + template< class U >
1.453 + iterator insert( std::auto_ptr<U> x )
1.454 + {
1.455 + return insert( x.release() );
1.456 + }
1.457 +
1.458 + template< typename InputIterator >
1.459 + void insert( InputIterator first, InputIterator last ) // basic
1.460 + {
1.461 + set_basic_clone_and_insert( first, last );
1.462 + }
1.463 +
1.464 +#if defined(BOOST_NO_SFINAE) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
1.465 +#else
1.466 +
1.467 + template< class Range >
1.468 + BOOST_DEDUCED_TYPENAME
1.469 + boost::disable_if< ptr_container_detail::is_pointer_or_integral<Range> >::type
1.470 + insert( const Range& r )
1.471 + {
1.472 + insert( boost::begin(r), boost::end(r) );
1.473 + }
1.474 +
1.475 +#endif
1.476 +
1.477 + template< class PtrSetAdapter >
1.478 + void transfer( BOOST_DEDUCED_TYPENAME PtrSetAdapter::iterator object,
1.479 + PtrSetAdapter& from ) // strong
1.480 + {
1.481 + this->multi_transfer( object, from );
1.482 + }
1.483 +
1.484 + template< class PtrSetAdapter >
1.485 + size_type transfer( BOOST_DEDUCED_TYPENAME PtrSetAdapter::iterator first,
1.486 + BOOST_DEDUCED_TYPENAME PtrSetAdapter::iterator last,
1.487 + PtrSetAdapter& from ) // basic
1.488 + {
1.489 + return this->multi_transfer( first, last, from );
1.490 + }
1.491 +
1.492 +#if defined(BOOST_NO_SFINAE) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
1.493 +#else
1.494 +
1.495 + template< class PtrSetAdapter, class Range >
1.496 + BOOST_DEDUCED_TYPENAME boost::disable_if< boost::is_same< Range,
1.497 + BOOST_DEDUCED_TYPENAME PtrSetAdapter::iterator >, size_type >::type
1.498 + transfer( const Range& r, PtrSetAdapter& from ) // basic
1.499 + {
1.500 + return transfer( boost::begin(r), boost::end(r), from );
1.501 + }
1.502 +
1.503 +#endif
1.504 +
1.505 + template< class PtrSetAdapter >
1.506 + void transfer( PtrSetAdapter& from ) // basic
1.507 + {
1.508 + transfer( from.begin(), from.end(), from );
1.509 + BOOST_ASSERT( from.empty() );
1.510 + }
1.511 +
1.512 + };
1.513 +
1.514 +} // namespace 'boost'
1.515 +
1.516 +#endif