1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
|
// Boost.Assign library
//
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see http://www.boost.org/libs/assign/
//
#ifndef BOOST_ASSIGN_LIST_OF_HPP
#define BOOST_ASSIGN_LIST_OF_HPP
#if defined(_MSC_VER)
# pragma once
#endif
#include <boost/assign/assignment_exception.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/config.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/detail/yes_no_type.hpp>
#include <boost/type_traits/decay.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/mpl/if.hpp>
#include <deque>
#include <cstddef>
#include <utility>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/iteration/local.hpp>
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
// BCB requires full type definition for is_array<> to work correctly.
#include <boost/array.hpp>
#endif
namespace boost
{
// this here is necessary to avoid compiler error in <boost/array.hpp>
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
template< class T, std::size_t sz >
class array;
#endif
namespace assign_detail
{
/////////////////////////////////////////////////////////////////////////
// Part 0: common conversion code
/////////////////////////////////////////////////////////////////////////
template< class T >
struct assign_decay
{
//
// Add constness to array parameters
// to support string literals properly
//
typedef BOOST_DEDUCED_TYPENAME mpl::eval_if<
::boost::is_array<T>,
::boost::decay<const T>,
::boost::decay<T> >::type type;
};
template< class T, std::size_t sz >
type_traits::yes_type assign_is_array( const array<T,sz>* );
type_traits::no_type assign_is_array( ... );
template< class T, class U >
type_traits::yes_type assign_is_pair( const std::pair<T,U>* );
type_traits::no_type assign_is_pair( ... );
struct array_type_tag
{
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
private:
char dummy_; // BCB would by default use 8 bytes
#endif
};
struct adapter_type_tag
{
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
private:
char dummy_; // BCB would by default use 8 bytes
#endif
};
struct pair_type_tag
{
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
private:
char dummy_; // BCB would by default use 8 bytes
#endif
};
struct default_type_tag
{
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
private:
char dummy_; // BCB would by default use 8 bytes
#endif
};
template< class DerivedTAssign, class Iterator >
class converter
{
public: // Range operations
typedef Iterator iterator;
typedef Iterator const_iterator;
iterator begin() const
{
return static_cast<const DerivedTAssign*>(this)->begin();
}
iterator end() const
{
return static_cast<const DerivedTAssign*>(this)->end();
}
public:
template< class Container >
Container convert_to_container() const
{
static Container* c = 0;
BOOST_STATIC_CONSTANT( bool, is_array_flag = sizeof( assign_detail::assign_is_array( c ) )
== sizeof( type_traits::yes_type ) );
typedef BOOST_DEDUCED_TYPENAME mpl::if_c< is_array_flag,
array_type_tag,
default_type_tag >::type tag_type;
return convert<Container>( c, tag_type() );
}
private:
template< class Container >
Container convert( const Container*, default_type_tag ) const
{
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
// old Dinkumware doesn't support iterator type as template
Container result;
iterator it = begin(),
e = end();
while( it != e )
{
result.insert( result.end(), *it );
++it;
}
return result;
#else
return Container( begin(), end() );
#endif
}
template< class Array >
Array convert( const Array*, array_type_tag ) const
{
typedef BOOST_DEDUCED_TYPENAME Array::value_type value_type;
#if BOOST_WORKAROUND(BOOST_INTEL, <= 910 ) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580 )
BOOST_DEDUCED_TYPENAME remove_const<Array>::type ar;
#else
Array ar;
#endif
const std::size_t sz = ar.size();
if( sz < static_cast<const DerivedTAssign*>(this)->size() )
throw assign::assignment_exception( "array initialized with too many elements" );
std::size_t n = 0;
iterator i = begin(),
e = end();
for( ; i != e; ++i, ++n )
ar[n] = *i;
for( ; n < sz; ++n )
ar[n] = value_type();
return ar;
}
template< class Adapter >
Adapter convert_to_adapter( const Adapter* = 0 ) const
{
Adapter a;
iterator i = begin(),
e = end();
for( ; i != e; ++i )
a.push( *i );
return a;
}
private:
struct adapter_converter;
friend struct adapter_converter;
struct adapter_converter
{
const converter& gl;
adapter_converter( const converter& this_ ) : gl( this_ )
{}
adapter_converter( const adapter_converter& r )
: gl( r.gl )
{ }
template< class Adapter >
operator Adapter() const
{
return gl.convert_to_adapter<Adapter>();
}
};
public:
template< class Container >
Container to_container( Container& c ) const
{
return convert( &c, default_type_tag() );
}
adapter_converter to_adapter() const
{
return adapter_converter( *this );
}
template< class Adapter >
Adapter to_adapter( Adapter& a ) const
{
return this->convert_to_adapter( &a );
}
template< class Array >
Array to_array( Array& a ) const
{
return convert( &a, array_type_tag() );
}
};
template< class T, class I, class Range >
inline bool operator==( const converter<T,I>& l, const Range& r )
{
return ::boost::iterator_range_detail::equal( l, r );
}
template< class T, class I, class Range >
inline bool operator==( const Range& l, const converter<T,I>& r )
{
return r == l;
}
template< class T, class I, class Range >
inline bool operator!=( const converter<T,I>& l, const Range& r )
{
return !( l == r );
}
template< class T, class I, class Range >
inline bool operator!=( const Range& l, const converter<T,I>& r )
{
return !( l == r );
}
template< class T, class I, class Range >
inline bool operator<( const converter<T,I>& l, const Range& r )
{
return ::boost::iterator_range_detail::less_than( l, r );
}
template< class T, class I, class Range >
inline bool operator<( const Range& l, const converter<T,I>& r )
{
return ::boost::iterator_range_detail::less_than( l, r );
}
template< class T, class I, class Range >
inline bool operator>( const converter<T,I>& l, const Range& r )
{
return r < l;
}
template< class T, class I, class Range >
inline bool operator>( const Range& l, const converter<T,I>& r )
{
return r < l;
}
template< class T, class I, class Range >
inline bool operator<=( const converter<T,I>& l, const Range& r )
{
return !( l > r );
}
template< class T, class I, class Range >
inline bool operator<=( const Range& l, const converter<T,I>& r )
{
return !( l > r );
}
template< class T, class I, class Range >
inline bool operator>=( const converter<T,I>& l, const Range& r )
{
return !( l < r );
}
template< class T, class I, class Range >
inline bool operator>=( const Range& l, const converter<T,I>& r )
{
return !( l < r );
}
template< class T, class I, class Elem, class Traits >
inline std::basic_ostream<Elem,Traits>&
operator<<( std::basic_ostream<Elem, Traits>& Os,
const converter<T,I>& r )
{
return Os << ::boost::make_iterator_range( r.begin(), r.end() );
}
/////////////////////////////////////////////////////////////////////////
// Part 1: flexible, but inefficient interface
/////////////////////////////////////////////////////////////////////////
template< class T >
class generic_list :
public converter< generic_list< BOOST_DEDUCED_TYPENAME assign_decay<T>::type >,
BOOST_DEDUCED_TYPENAME std::deque<BOOST_DEDUCED_TYPENAME
assign_decay<T>::type>::iterator >
{
typedef BOOST_DEDUCED_TYPENAME assign_decay<T>::type Ty;
typedef std::deque<Ty> impl_type;
mutable impl_type values_;
public:
typedef BOOST_DEDUCED_TYPENAME impl_type::iterator iterator;
typedef iterator const_iterator;
typedef BOOST_DEDUCED_TYPENAME impl_type::value_type value_type;
typedef BOOST_DEDUCED_TYPENAME impl_type::size_type size_type;
typedef BOOST_DEDUCED_TYPENAME impl_type::difference_type difference_type;
public:
iterator begin() const { return values_.begin(); }
iterator end() const { return values_.end(); }
bool empty() const { return values_.empty(); }
size_type size() const { return values_.size(); }
private:
void push_back( value_type r ) { values_.push_back( r ); }
public:
generic_list& operator,( const Ty& u )
{
this->push_back( u );
return *this;
}
generic_list& operator()()
{
this->push_back( Ty() );
return *this;
}
generic_list& operator()( const Ty& u )
{
this->push_back( u );
return *this;
}
#ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value
#define BOOST_ASSIGN_MAX_PARAMS 5
#endif
#define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
#define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class U)
#define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, U, const& u)
#define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, u)
#define BOOST_ASSIGN_PARAMS4(n) BOOST_PP_ENUM_PARAMS(n, U)
#define BOOST_ASSIGN_PARAMS2_NO_REF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, U, u)
#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
#define BOOST_PP_LOCAL_MACRO(n) \
template< class U, BOOST_ASSIGN_PARAMS1(n) > \
generic_list& operator()(U const& u, BOOST_ASSIGN_PARAMS2(n) ) \
{ \
this->push_back( Ty(u, BOOST_ASSIGN_PARAMS3(n))); \
return *this; \
} \
/**/
#include BOOST_PP_LOCAL_ITERATE()
template< class U >
generic_list& repeat( std::size_t sz, U u )
{
std::size_t i = 0;
while( i++ != sz )
this->push_back( u );
return *this;
}
template< class Nullary_function >
generic_list& repeat_fun( std::size_t sz, Nullary_function fun )
{
std::size_t i = 0;
while( i++ != sz )
this->push_back( fun() );
return *this;
}
template< class SinglePassIterator >
generic_list& range( SinglePassIterator first,
SinglePassIterator last )
{
for( ; first != last; ++first )
this->push_back( *first );
return *this;
}
template< class SinglePassRange >
generic_list& range( const SinglePassRange& r )
{
return range( boost::begin(r), boost::end(r) );
}
template< class Container >
operator Container() const
{
return this-> BOOST_NESTED_TEMPLATE convert_to_container<Container>();
}
};
/////////////////////////////////////////////////////////////////////////
// Part 2: efficient, but inconvenient interface
/////////////////////////////////////////////////////////////////////////
template< class T >
struct assign_reference
{
assign_reference()
{ /* intentionally empty */ }
assign_reference( T& r ) : ref_(&r)
{ }
void operator=( T& r )
{
ref_ = &r;
}
operator T&() const
{
return *ref_;
}
void swap( assign_reference& r )
{
std::swap( *ref_, *r.ref_ );
}
T& get_ref() const
{
return *ref_;
}
private:
T* ref_;
};
template< class T >
inline bool operator<( const assign_reference<T>& l,
const assign_reference<T>& r )
{
return l.get_ref() < r.get_ref();
}
template< class T >
inline bool operator>( const assign_reference<T>& l,
const assign_reference<T>& r )
{
return l.get_ref() > r.get_ref();
}
template< class T >
inline void swap( assign_reference<T>& l,
assign_reference<T>& r )
{
l.swap( r );
}
template< class T, int N >
struct static_generic_list :
public converter< static_generic_list<T,N>, assign_reference<T>* >
{
private:
typedef T internal_value_type;
public:
typedef assign_reference<internal_value_type> value_type;
typedef value_type* iterator;
typedef value_type* const_iterator;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
static_generic_list( T& r ) :
current_(1)
{
refs_[0] = r;
}
static_generic_list& operator()( T& r )
{
insert( r );
return *this;
}
iterator begin() const
{
return &refs_[0];
}
iterator end() const
{
return &refs_[current_];
}
size_type size() const
{
return static_cast<size_type>( current_ );
}
bool empty() const
{
return false;
}
template< class ForwardIterator >
static_generic_list& range( ForwardIterator first,
ForwardIterator last )
{
for( ; first != last; ++first )
this->insert( *first );
return *this;
}
template< class ForwardRange >
static_generic_list& range( ForwardRange& r )
{
return range( boost::begin(r), boost::end(r) );
}
template< class ForwardRange >
static_generic_list& range( const ForwardRange& r )
{
return range( boost::begin(r), boost::end(r) );
}
template< class Container >
operator Container() const
{
return this-> BOOST_NESTED_TEMPLATE convert_to_container<Container>();
}
private:
void insert( T& r )
{
refs_[current_] = r;
++current_;
}
static_generic_list();
mutable assign_reference<internal_value_type> refs_[N];
int current_;
};
} // namespace 'assign_detail'
namespace assign
{
template< class T >
inline assign_detail::generic_list<T>
list_of()
{
return assign_detail::generic_list<T>()( T() );
}
template< class T >
inline assign_detail::generic_list<T>
list_of( const T& t )
{
return assign_detail::generic_list<T>()( t );
}
template< int N, class T >
inline assign_detail::static_generic_list< BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<T>::type,N>
ref_list_of( T& t )
{
return assign_detail::static_generic_list<BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<T>::type,N>( t );
}
template< int N, class T >
inline assign_detail::static_generic_list<const BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<T>::type,N>
cref_list_of( const T& t )
{
return assign_detail::static_generic_list<const BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<T>::type,N>( t );
}
#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
#define BOOST_PP_LOCAL_MACRO(n) \
template< class T, class U, BOOST_ASSIGN_PARAMS1(n) > \
inline assign_detail::generic_list<T> \
list_of(U const& u, BOOST_ASSIGN_PARAMS2(n) ) \
{ \
return assign_detail::generic_list<T>()(u, BOOST_ASSIGN_PARAMS3(n)); \
} \
/**/
#include BOOST_PP_LOCAL_ITERATE()
#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
#define BOOST_PP_LOCAL_MACRO(n) \
template< class U, BOOST_ASSIGN_PARAMS1(n) > \
inline assign_detail::generic_list< tuple<U, BOOST_ASSIGN_PARAMS4(n)> > \
tuple_list_of(U u, BOOST_ASSIGN_PARAMS2_NO_REF(n) ) \
{ \
return assign_detail::generic_list< tuple<U, BOOST_ASSIGN_PARAMS4(n)> >()( tuple<U,BOOST_ASSIGN_PARAMS4(n)>( u, BOOST_ASSIGN_PARAMS3(n) )); \
} \
/**/
#include BOOST_PP_LOCAL_ITERATE()
template< class Key, class T >
inline assign_detail::generic_list< std::pair
<
BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<Key>::type,
BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<T>::type
> >
map_list_of( const Key& k, const T& t )
{
typedef BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<Key>::type k_type;
typedef BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<T>::type t_type;
return assign_detail::generic_list< std::pair<k_type,t_type> >()( k, t );
}
template< class F, class S >
inline assign_detail::generic_list< std::pair
<
BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<F>::type,
BOOST_DEDUCED_TYPENAME assign_detail::assign_decay<S>::type
> >
pair_list_of( const F& f, const S& s )
{
return map_list_of( f, s );
}
} // namespace 'assign'
} // namespace 'boost'
#undef BOOST_ASSIGN_PARAMS1
#undef BOOST_ASSIGN_PARAMS2
#undef BOOST_ASSIGN_PARAMS3
#undef BOOST_ASSIGN_PARAMS4
#undef BOOST_ASSIGN_PARAMS2_NO_REF
#undef BOOST_ASSIGN_MAX_PARAMETERS
#endif
|