PageRenderTime 68ms CodeModel.GetById 20ms app.highlight 40ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/interprocess/detail/move.hpp

http://hadesmem.googlecode.com/
C++ Header | 1157 lines | 623 code | 223 blank | 311 comment | 26 complexity | 67e45e127a10e6e967f36694b3d586ea MD5 | raw file
   1//////////////////////////////////////////////////////////////////////////////
   2//
   3// (C) Copyright David Abrahams, Vicente Botet 2009.
   4// (C) Copyright Ion Gaztanaga 2009-2010.
   5// Distributed under the Boost Software License, Version 1.0.
   6// (See accompanying file LICENSE_1_0.txt or copy at
   7// http://www.boost.org/LICENSE_1_0.txt)
   8//
   9// See http://www.boost.org/libs/move for documentation.
  10//
  11//////////////////////////////////////////////////////////////////////////////
  12
  13//! \file
  14
  15#ifndef BOOST_MOVE_DETAIL_MOVE_HPP
  16#define BOOST_MOVE_DETAIL_MOVE_HPP
  17
  18#include <boost/config.hpp>
  19#include <algorithm> //copy, copy_backward
  20#include <memory>    //uninitialized_copy
  21#include <iterator>  //std::iterator
  22#include <boost/mpl/if.hpp>
  23#include <boost/utility/enable_if.hpp>
  24#include <boost/mpl/bool.hpp>
  25#include <boost/type_traits/has_trivial_destructor.hpp>
  26#include <boost/utility/addressof.hpp>
  27
  28//! Defining or undefining this macro will change Boost.Move behaviour 
  29//! for copyable and movable classes when assigning from non-const rvalues:
  30//! \code
  31//! copyable_and_movable produce(){ return copyable_and_movable(); }
  32//! \endcode
  33//! If the macro is NOT defined:
  34//! \code
  35//! copyable_and_movable cm;
  36//! cm = copyable_and_movable(); //object is COPIED (missed optimization)
  37//! \endcode
  38//! If the macro IS defined:
  39//! \code
  40//! copyable_and_movable cm;
  41//! cm = copyable_and_movable(); //object is MOVED
  42//! \endcode
  43//! However, the second option has also some downsides. See documentation for more details.
  44#define BOOST_MOVE_OPTIMIZED_EMULATION
  45
  46/// @cond
  47
  48//Define to easily port between Boost.Move and internal Boost.Interprocess move emulation
  49//
  50// This configuration is temporary. Boost.Interprocess emulation uses
  51// different macros to avoid any redefinition of a top-levl Boost macro.
  52// It will disappear once the library is accepted and
  53// Boost.Interprocess is updated to the standard interface. 
  54//
  55#define BOOST_MOVE_IN_BOOST_INTERPROCESS_NAMESPACE
  56
  57#ifdef BOOST_MOVE_IN_BOOST_INTERPROCESS_NAMESPACE
  58
  59#define INTERPROCESS_NAMESPACE_BEGIN namespace interprocess {
  60#define INTERPROCESS_NAMESPACE_END }// namespace interprocess {
  61#define BOOST_MOVE_NAMESPACE boost::interprocess
  62
  63#else    //BOOST_MOVE_IN_BOOST_INTERPROCESS_NAMESPACE
  64
  65#define INTERPROCESS_NAMESPACE_BEGIN
  66#define INTERPROCESS_NAMESPACE_END
  67#define BOOST_MOVE_NAMESPACE boost
  68
  69#endif   //BOOST_MOVE_IN_BOOST_INTERPROCESS_NAMESPACE
  70
  71namespace boost {
  72INTERPROCESS_NAMESPACE_BEGIN
  73namespace move_detail {
  74
  75template <class T>
  76struct identity
  77{
  78   typedef T type;
  79};
  80
  81template <class T, class U>
  82class is_convertible
  83{
  84   typedef char true_t;
  85   class false_t { char dummy[2]; };
  86   static true_t dispatch(U);
  87   static false_t dispatch(...);
  88   static T trigger();
  89   public:
  90   enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) };
  91};
  92
  93}  //namespace move_detail {
  94INTERPROCESS_NAMESPACE_END
  95}  //namespace boost {
  96
  97/// @endcond
  98
  99#if !defined(BOOST_NO_RVALUE_REFERENCES)
 100
 101#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 5)
 102
 103#define BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
 104
 105#else
 106
 107#if defined(_MSC_VER) && (_MSC_VER == 1600)
 108#define BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG
 109#endif
 110
 111#endif
 112
 113#endif
 114
 115
 116#if defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED)
 117
 118#include <boost/type_traits/is_fundamental.hpp>
 119#include <boost/type_traits/is_pointer.hpp>
 120#include <boost/type_traits/is_same.hpp>
 121
 122#ifdef __GNUC__ 
 123#   define BOOST_MOVE_ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__)) 
 124#else 
 125#   define BOOST_MOVE_ATTRIBUTE_MAY_ALIAS 
 126#endif
 127
 128namespace boost {
 129INTERPROCESS_NAMESPACE_BEGIN
 130
 131//////////////////////////////////////////////////////////////////////////////
 132//
 133//                            struct rv
 134//
 135//////////////////////////////////////////////////////////////////////////////
 136template <class T>
 137class rv : public T
 138{
 139   rv();
 140   ~rv();
 141   rv(rv const&);
 142   void operator=(rv const&);
 143} BOOST_MOVE_ATTRIBUTE_MAY_ALIAS;
 144
 145//////////////////////////////////////////////////////////////////////////////
 146//
 147//                            move_detail::is_rv
 148//
 149//////////////////////////////////////////////////////////////////////////////
 150
 151namespace move_detail {
 152
 153template <class T>
 154struct is_rv
 155{
 156   static const bool value = false;
 157};
 158
 159template <class T>
 160struct is_rv< rv<T> >
 161{
 162   static const bool value = true;
 163};
 164
 165}  //namespace move_detail {
 166
 167//////////////////////////////////////////////////////////////////////////////
 168//
 169//                               is_movable
 170//
 171//////////////////////////////////////////////////////////////////////////////
 172template<class T>
 173struct is_movable
 174   : public ::boost::mpl::bool_<move_detail::is_convertible<T, rv<T>&>::value>
 175{
 176};
 177
 178template<class T>
 179struct is_movable< rv<T> >
 180   : public ::boost::mpl::bool_<false>
 181{
 182};
 183
 184template <class T> 
 185struct has_nothrow_move
 186   : public ::boost::mpl::bool_<false>
 187{
 188};
 189
 190//////////////////////////////////////////////////////////////////////////////
 191//
 192//                            move()
 193//
 194//////////////////////////////////////////////////////////////////////////////
 195template <class T>
 196typename ::boost::disable_if<is_movable<T>, T&>::type move(T& x)
 197{
 198   return x;
 199}
 200
 201template <class T>
 202typename enable_if<is_movable<T>, rv<T>&>::type move(T& x)
 203{
 204   return *static_cast<rv<T>* >(boost::addressof(x));
 205}
 206
 207template <class T>
 208typename enable_if<is_movable<T>, rv<T>&>::type move(rv<T>& x)
 209{
 210   return x;
 211}
 212
 213
 214#define BOOST_RV_REF(TYPE)\
 215   ::BOOST_MOVE_NAMESPACE::rv< TYPE >& \
 216//
 217
 218#define BOOST_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
 219   ::BOOST_MOVE_NAMESPACE::rv< TYPE<ARG1, ARG2> >& \
 220//
 221
 222#define BOOST_RV_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)\
 223   ::BOOST_MOVE_NAMESPACE::rv< TYPE<ARG1, ARG2, ARG3> >& \
 224//
 225
 226
 227#define BOOST_FWD_REF(TYPE)\
 228   const TYPE & \
 229//
 230
 231#define BOOST_CATCH_CONST_RLVALUE(TYPE)\
 232   const ::BOOST_MOVE_NAMESPACE::rv< TYPE >& \
 233//
 234
 235#ifdef BOOST_MOVE_OPTIMIZED_EMULATION
 236
 237#define BOOST_COPY_ASSIGN_REF(TYPE)\
 238   const ::BOOST_MOVE_NAMESPACE::rv< TYPE >& \
 239//
 240
 241#define BOOST_MOVE_MACRO_COPY_ASSIGN_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
 242   const ::BOOST_MOVE_NAMESPACE::rv< TYPE<ARG1, ARG2> >& \
 243//
 244
 245#define BOOST_MOVE_MACRO_COPY_ASSIGN_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)\
 246   const ::BOOST_MOVE_NAMESPACE::rv< TYPE<ARG1, ARG2, ARG3> >& \
 247//
 248
 249//////////////////////////////////////////////////////////////////////////////
 250//
 251//                            forward()
 252//
 253//////////////////////////////////////////////////////////////////////////////
 254
 255template <class T>
 256typename enable_if< ::BOOST_MOVE_NAMESPACE::move_detail::is_rv<T>, T &>::type
 257   forward(const typename move_detail::identity<T>::type &x)
 258{
 259   return const_cast<T&>(x);
 260}
 261
 262template <class T>
 263typename disable_if< ::BOOST_MOVE_NAMESPACE::move_detail::is_rv<T>, const T &>::type
 264   forward(const typename move_detail::identity<T>::type &x)
 265{
 266   return x;
 267}
 268
 269#else //BOOST_MOVE_OPTIMIZED_EMULATION
 270
 271#define BOOST_COPY_ASSIGN_REF(TYPE)\
 272   const TYPE & \
 273//
 274
 275#define BOOST_MOVE_MACRO_COPY_ASSIGN_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
 276   const TYPE< ARG1, ARG2 >& \
 277//
 278
 279#define BOOST_MOVE_MACRO_COPY_ASSIGN_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)\
 280   const TYPE< ARG1, ARG2, ARG3 > & \
 281//
 282
 283//////////////////////////////////////////////////////////////////////////////
 284//
 285//                            forward()
 286//
 287//////////////////////////////////////////////////////////////////////////////
 288
 289//Catches const lvalues for movable types
 290template <class T>
 291const T&
 292   forward( BOOST_CATCH_CONST_RLVALUE(T) x 
 293          , typename ::boost::enable_if_c< ::BOOST_MOVE_NAMESPACE::is_movable<T>::value >::type* = 0)
 294{
 295   return static_cast<const T&>(x);
 296}
 297
 298//Catches const lvalues for non-movable types
 299template <class T>
 300const T&
 301   forward( const T &x 
 302          , typename ::boost::enable_if_c< !::BOOST_MOVE_NAMESPACE::is_movable<T>::value &&
 303                                            !::boost::move_detail::is_rv<T>::value
 304                                          >::type* = 0)
 305{
 306   return static_cast<const T&>(x);
 307}
 308
 309//Catches forwarded ::boost::rv<T> via BOOST_FWD_REFs 
 310template <class T>
 311T &
 312   forward( const T &t
 313          , typename ::boost::enable_if_c< ::boost::move_detail::is_rv<T>::value >::type* = 0)
 314{
 315   return const_cast<T&>(t);
 316}
 317
 318//Catches forwarded ::boost::rv<T>
 319template <class T, class U>
 320const T &
 321   forward( const U &u
 322          , typename ::boost::enable_if_c< ::boost::is_same< ::boost::rv<T>, U >::value >::type * = 0)
 323{
 324   return static_cast<const T&>(u);
 325}
 326
 327//Catches non-const lvalues
 328template <class T>
 329T&
 330   forward( typename move_detail::identity<T>::type &x
 331          , typename ::boost::enable_if_c< !::boost::move_detail::is_rv<T>::value >::type* = 0)
 332{
 333   return x;
 334}
 335
 336//Catches non-const rvalues
 337template <class T>
 338typename enable_if<is_movable<T>, ::boost::rv<T> & >::type
 339   forward(BOOST_RV_REF(T) x)
 340{  return x;   }
 341
 342#endif
 343
 344//////////////////////////////////////////////////////////////////////////////
 345//
 346//                         BOOST_MOVABLE_BUT_NOT_COPYABLE
 347//
 348//////////////////////////////////////////////////////////////////////////////
 349#define BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE)\
 350   private:\
 351   TYPE(TYPE &);\
 352   TYPE& operator=(TYPE &);\
 353   public:\
 354   operator ::BOOST_MOVE_NAMESPACE::rv<TYPE>&() \
 355   {  return *static_cast< ::BOOST_MOVE_NAMESPACE::rv<TYPE>* >(this);  }\
 356   operator const ::BOOST_MOVE_NAMESPACE::rv<TYPE>&() const \
 357   {  return *static_cast<const ::BOOST_MOVE_NAMESPACE::rv<TYPE>* >(this);  }\
 358   private:\
 359//
 360
 361//////////////////////////////////////////////////////////////////////////////
 362//
 363//                         BOOST_COPYABLE_AND_MOVABLE
 364//
 365//////////////////////////////////////////////////////////////////////////////
 366
 367#ifdef BOOST_MOVE_OPTIMIZED_EMULATION
 368
 369#define BOOST_COPYABLE_AND_MOVABLE(TYPE)\
 370   public:\
 371   TYPE& operator=(TYPE &t)\
 372   {  this->operator=(static_cast<const ::BOOST_MOVE_NAMESPACE::rv<TYPE> &>(const_cast<const TYPE &>(t))); return *this;}\
 373   public:\
 374   operator ::BOOST_MOVE_NAMESPACE::rv<TYPE>&() \
 375   {  return *static_cast< ::BOOST_MOVE_NAMESPACE::rv<TYPE>* >(this);  }\
 376   operator const ::BOOST_MOVE_NAMESPACE::rv<TYPE>&() const \
 377   {  return *static_cast<const ::BOOST_MOVE_NAMESPACE::rv<TYPE>* >(this);  }\
 378   private:\
 379//
 380
 381#else //#ifdef BOOST_MOVE_OPTIMIZED_EMULATION
 382
 383#define BOOST_COPYABLE_AND_MOVABLE(TYPE)\
 384   public:\
 385   operator ::BOOST_MOVE_NAMESPACE::rv<TYPE>&() \
 386   {  return *static_cast< ::BOOST_MOVE_NAMESPACE::rv<TYPE>* >(this);  }\
 387   operator const ::BOOST_MOVE_NAMESPACE::rv<TYPE>&() const \
 388   {  return *static_cast<const ::BOOST_MOVE_NAMESPACE::rv<TYPE>* >(this);  }\
 389   private:\
 390//
 391
 392#endif
 393
 394
 395INTERPROCESS_NAMESPACE_END
 396}  //namespace boost
 397
 398#else    //BOOST_NO_RVALUE_REFERENCES
 399
 400#include <boost/type_traits/remove_reference.hpp>
 401
 402namespace boost {
 403INTERPROCESS_NAMESPACE_BEGIN
 404
 405/// @cond
 406
 407namespace move_detail {
 408
 409template<class T>
 410struct is_lvalue_reference
 411   : public ::boost::mpl::bool_<false>
 412{};
 413
 414template<class T>
 415struct is_lvalue_reference<T&>
 416   : public ::boost::mpl::bool_<true>
 417{};
 418
 419typedef char one;
 420struct two {one _[2];};
 421
 422template <class T>
 423struct internal_member_value_traits
 424{
 425   template <class U> static one test(...);
 426   template <class U> static two test(typename U::boost_move_emulation_t* = 0);
 427   static const bool value = sizeof(test<T>(0)) == sizeof(two);
 428};
 429
 430}  //namespace move_detail {
 431
 432/// @endcond
 433
 434//////////////////////////////////////////////////////////////////////////////
 435//
 436//                               is_movable
 437//
 438//////////////////////////////////////////////////////////////////////////////
 439
 440//! For compilers with rvalue references, this traits class returns true
 441//! if BOOST_ENABLE_MOVE_EMULATION is activated.
 442//!
 443//! For other compilers returns true if T is convertible to <i>::boost::rv<T>&</i>
 444template<class T>
 445struct is_movable
 446   : public ::boost::mpl::bool_<move_detail::internal_member_value_traits<T>::value>
 447{
 448};
 449
 450//! By default this traits returns false. Classes with non-thworing move construction
 451//! and assignment should specialize this trait to obtain some performance improvements.
 452template <class T> 
 453struct has_nothrow_move
 454   : public ::boost::mpl::bool_<false>
 455{};
 456
 457//////////////////////////////////////////////////////////////////////////////
 458//
 459//                                  move
 460//
 461//////////////////////////////////////////////////////////////////////////////
 462
 463
 464#if defined(BOOST_MOVE_DOXYGEN_INVOKED)
 465//! This function provides a way to convert a reference into a rvalue reference
 466//! in compilers with rvalue references. For other compilers converts T & into
 467//! <i>::boost::rv<T> &</i> so that move emulation is activated.
 468template <class T> inline 
 469rvalue_reference move (input_reference);
 470
 471#else //BOOST_MOVE_DOXYGEN_INVOKED
 472
 473#if defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
 474
 475//Old move approach, lvalues could bind to rvalue references
 476template <class T> inline
 477typename remove_reference<T>::type && move(T&& t)
 478{  return t;   }
 479
 480#else //Old move
 481
 482template <class T> inline
 483typename remove_reference<T>::type && move(T&& t)
 484{ return static_cast<typename remove_reference<T>::type &&>(t); } 
 485
 486#endif   //Old move
 487
 488#endif   //BOOST_MOVE_DOXYGEN_INVOKED
 489
 490
 491//////////////////////////////////////////////////////////////////////////////
 492//
 493//                                  forward
 494//
 495//////////////////////////////////////////////////////////////////////////////
 496
 497
 498#if defined(BOOST_MOVE_DOXYGEN_INVOKED)
 499//! This function provides limited form of forwarding that is usually enough for
 500//! in-place construction and avoids the exponential overloading necessary for
 501//! perfect forwarding in C++03.
 502//!
 503//! For compilers with rvalue references this function provides perfect forwarding.
 504//!
 505//! Otherwise:
 506//! * If input_reference binds to const ::boost::rv<T> & then it output_reference is
 507//!   ::boost::rev<T> &
 508//!
 509//! * Else, input_reference is equal to output_reference is equal to input_reference.
 510template <class T> inline output_reference forward(input_reference);
 511
 512#else
 513
 514#if defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
 515
 516//Old move approach, lvalues could bind to rvalue references
 517
 518template <class T> inline
 519T&& forward (typename move_detail::identity<T>::type&& t)
 520{  return t;   }
 521
 522#else //Old move
 523
 524//Implementation #5 from N2951, thanks to Howard Hinnant
 525
 526template <class T, class U>
 527inline T&& forward(U&& t
 528    , typename enable_if_c<
 529      move_detail::is_lvalue_reference<T>::value ? move_detail::is_lvalue_reference<U>::value : true>::type * = 0/*
 530    , typename enable_if_c<
 531      move_detail::is_convertible
 532         <typename remove_reference<U>::type*, typename remove_reference<T>::type*>::value>::type * = 0*/)
 533{ return static_cast<T&&>(t);   }
 534
 535#endif   //Old move
 536
 537#endif   //BOOST_MOVE_DOXYGEN_INVOKED
 538
 539//////////////////////////////////////////////////////////////////////////////
 540//
 541//                         BOOST_ENABLE_MOVE_EMULATION
 542//
 543//////////////////////////////////////////////////////////////////////////////
 544
 545///@cond
 546
 547#define BOOST_ENABLE_MOVE_EMULATION(TYPE)\
 548   typedef int boost_move_emulation_t;
 549\
 550//
 551
 552/// @endcond
 553
 554//! This macro marks a type as movable but not copyable, disabling copy construction
 555//! and assignment. The user will need to write a move constructor/assignment as explained
 556//! in the documentation to fully write a movable but not copyable class.
 557#define BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE)\
 558   public:\
 559   typedef int boost_move_emulation_t;\
 560   private:\
 561   TYPE(const TYPE &);\
 562   TYPE& operator=(const TYPE &);\
 563//
 564
 565//! This macro marks a type as copyable and movable.
 566//! The user will need to write a move constructor/assignment and a copy assignment
 567//! as explained in the documentation to fully write a copyable and movable class.
 568#define BOOST_COPYABLE_AND_MOVABLE(TYPE)\
 569   typedef int boost_move_emulation_t;
 570//
 571
 572/// @cond
 573
 574#define BOOST_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
 575   TYPE<ARG1, ARG2> && \
 576//
 577
 578#define BOOST_RV_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)\
 579   TYPE<ARG1, ARG2, ARG3> && \
 580//
 581
 582/// @endcond
 583
 584//!This macro is used to achieve portable syntax in move
 585//!constructors and assignments for classes marked as
 586//!BOOST_COPYABLE_AND_MOVABLE or BOOST_MOVABLE_BUT_NOT_COPYABLE
 587#define BOOST_RV_REF(TYPE)\
 588   TYPE && \
 589//
 590
 591//!This macro is used to achieve portable syntax in copy
 592//!assignment for classes marked as BOOST_COPYABLE_AND_MOVABLE.
 593#define BOOST_COPY_ASSIGN_REF(TYPE)\
 594   const TYPE & \
 595//
 596
 597/// @cond
 598
 599#define BOOST_COPY_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
 600   const TYPE<ARG1, ARG2> & \
 601//
 602
 603#define BOOST_COPY_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)\
 604   TYPE<ARG1, ARG2, ARG3>& \
 605//
 606
 607/// @endcond
 608
 609//! This macro is used to implement portable perfect forwarding
 610//! as explained in the documentation.
 611#define BOOST_FWD_REF(TYPE)\
 612   TYPE && \
 613//
 614
 615/// @cond
 616
 617#define BOOST_CATCH_CONST_RLVALUE(TYPE)\
 618   const TYPE & \
 619//
 620
 621/// @endcond
 622
 623INTERPROCESS_NAMESPACE_END
 624}  //namespace boost {
 625
 626#endif   //BOOST_NO_RVALUE_REFERENCES
 627
 628namespace boost {
 629INTERPROCESS_NAMESPACE_BEGIN
 630
 631//////////////////////////////////////////////////////////////////////////////
 632//
 633//                            move_iterator
 634//
 635//////////////////////////////////////////////////////////////////////////////
 636
 637//! Class template move_iterator is an iterator adaptor with the same behavior
 638//! as the underlying iterator except that its dereference operator implicitly
 639//! converts the value returned by the underlying iterator's dereference operator
 640//! to an rvalue reference. Some generic algorithms can be called with move
 641//! iterators to replace copying with moving.
 642template <class It>
 643class move_iterator
 644{
 645   public:
 646   typedef It                                                              iterator_type;
 647   typedef typename std::iterator_traits<iterator_type>::value_type        value_type;
 648   #if !defined(BOOST_NO_RVALUE_REFERENCES) || defined(BOOST_MOVE_DOXYGEN_INVOKED)
 649   typedef value_type &&                                                   reference;
 650   #else
 651   typedef typename ::boost::mpl::if_
 652      < ::BOOST_MOVE_NAMESPACE::is_movable<value_type>
 653      , ::BOOST_MOVE_NAMESPACE::rv<value_type>&
 654      , value_type & >::type                                               reference;
 655   #endif
 656   typedef It                                                              pointer;
 657   typedef typename std::iterator_traits<iterator_type>::difference_type   difference_type;
 658   typedef typename std::iterator_traits<iterator_type>::iterator_category iterator_category;
 659
 660   move_iterator()
 661   {}
 662
 663   explicit move_iterator(It i)
 664      :  m_it(i)
 665   {}
 666
 667   template <class U>
 668   move_iterator(const move_iterator<U>& u)
 669      :  m_it(u.base())
 670   {}
 671
 672   iterator_type base() const
 673   {  return m_it;   }
 674
 675   reference operator*() const
 676   {
 677      #if defined(BOOST_NO_RVALUE_REFERENCES) || defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
 678      return *m_it;
 679      #else
 680      return ::BOOST_MOVE_NAMESPACE::move(*m_it);
 681      #endif
 682   }
 683
 684   pointer   operator->() const
 685   {  return m_it;   }
 686
 687   move_iterator& operator++()
 688   {  ++m_it; return *this;   }
 689
 690   move_iterator<iterator_type>  operator++(int)
 691   {  move_iterator<iterator_type> tmp(*this); ++(*this); return tmp;   }
 692
 693   move_iterator& operator--()
 694   {  --m_it; return *this;   }
 695
 696   move_iterator<iterator_type>  operator--(int)
 697   {  move_iterator<iterator_type> tmp(*this); --(*this); return tmp;   }
 698
 699   move_iterator<iterator_type>  operator+ (difference_type n) const
 700   {  return move_iterator<iterator_type>(m_it + n);  }
 701
 702   move_iterator& operator+=(difference_type n)
 703   {  m_it += n; return *this;   }
 704
 705   move_iterator<iterator_type>  operator- (difference_type n) const
 706   {  return move_iterator<iterator_type>(m_it - n);  }
 707
 708   move_iterator& operator-=(difference_type n)
 709   {  m_it -= n; return *this;   }
 710
 711   reference operator[](difference_type n) const
 712   {
 713      #if defined(BOOST_NO_RVALUE_REFERENCES) || defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
 714      return m_it[n];
 715      #else
 716      return ::BOOST_MOVE_NAMESPACE::move(m_it[n]);
 717      #endif
 718   }
 719
 720   friend bool operator==(const move_iterator& x, const move_iterator& y)
 721   {  return x.base() == y.base();  }
 722
 723   friend bool operator!=(const move_iterator& x, const move_iterator& y)
 724   {  return x.base() != y.base();  }
 725
 726   friend bool operator< (const move_iterator& x, const move_iterator& y)
 727   {  return x.base() < y.base();   }
 728
 729   friend bool operator<=(const move_iterator& x, const move_iterator& y)
 730   {  return x.base() <= y.base();  }
 731
 732   friend bool operator> (const move_iterator& x, const move_iterator& y)
 733   {  return x.base() > y.base();  }
 734
 735   friend bool operator>=(const move_iterator& x, const move_iterator& y)
 736   {  return x.base() >= y.base();  }
 737
 738   friend difference_type operator-(const move_iterator& x, const move_iterator& y)
 739   {  return x.base() - y.base();   }
 740
 741   friend move_iterator operator+(difference_type n, const move_iterator& x)
 742   {  return move_iterator(x.base() + n);   }
 743
 744   private:
 745   It m_it;
 746};
 747
 748
 749//is_move_iterator
 750namespace move_detail {
 751
 752template <class I>
 753struct is_move_iterator
 754   : public ::boost::mpl::bool_<false>
 755{
 756};
 757
 758template <class I>
 759struct is_move_iterator< ::BOOST_MOVE_NAMESPACE::move_iterator<I> >
 760   : public ::boost::mpl::bool_<true>
 761{
 762};
 763
 764}  //namespace move_detail {
 765
 766//////////////////////////////////////////////////////////////////////////////
 767//
 768//                            move_iterator
 769//
 770//////////////////////////////////////////////////////////////////////////////
 771
 772//!
 773//! <b>Returns</b>: move_iterator<It>(i).
 774template<class It>
 775move_iterator<It> make_move_iterator(const It &it)
 776{  return move_iterator<It>(it); }
 777
 778//////////////////////////////////////////////////////////////////////////////
 779//
 780//                         back_move_insert_iterator
 781//
 782//////////////////////////////////////////////////////////////////////////////
 783
 784
 785//! A move insert iterator that move constructs elements at the
 786//! back of a container
 787template <typename C> // C models Container
 788class back_move_insert_iterator
 789   : public std::iterator<std::output_iterator_tag, void, void, void, void>
 790{
 791   C* container_m;
 792
 793   public:
 794   typedef C container_type;
 795
 796   explicit back_move_insert_iterator(C& x) : container_m(&x) { }
 797
 798   back_move_insert_iterator& operator=(typename C::reference x)
 799   { container_m->push_back(BOOST_MOVE_NAMESPACE::move(x)); return *this; }
 800
 801   back_move_insert_iterator& operator*()     { return *this; }
 802   back_move_insert_iterator& operator++()    { return *this; }
 803   back_move_insert_iterator& operator++(int) { return *this; }
 804};
 805
 806//!
 807//! <b>Returns</b>: back_move_insert_iterator<C>(x).
 808template <typename C> // C models Container
 809inline back_move_insert_iterator<C> back_move_inserter(C& x)
 810{
 811   return back_move_insert_iterator<C>(x);
 812}
 813
 814//////////////////////////////////////////////////////////////////////////////
 815//
 816//                         front_move_insert_iterator
 817//
 818//////////////////////////////////////////////////////////////////////////////
 819
 820//! A move insert iterator that move constructs elements int the
 821//! front of a container
 822template <typename C> // C models Container
 823class front_move_insert_iterator
 824   : public std::iterator<std::output_iterator_tag, void, void, void, void>
 825{
 826   C* container_m;
 827
 828public:
 829   typedef C container_type;
 830
 831   explicit front_move_insert_iterator(C& x) : container_m(&x) { }
 832
 833   front_move_insert_iterator& operator=(typename C::reference x)
 834   { container_m->push_front(BOOST_MOVE_NAMESPACE::move(x)); return *this; }
 835
 836   front_move_insert_iterator& operator*()     { return *this; }
 837   front_move_insert_iterator& operator++()    { return *this; }
 838   front_move_insert_iterator& operator++(int) { return *this; }
 839};
 840
 841//!
 842//! <b>Returns</b>: front_move_insert_iterator<C>(x).
 843template <typename C> // C models Container
 844inline front_move_insert_iterator<C> front_move_inserter(C& x)
 845{
 846   return front_move_insert_iterator<C>(x);
 847}
 848
 849//////////////////////////////////////////////////////////////////////////////
 850//
 851//                         insert_move_iterator
 852//
 853//////////////////////////////////////////////////////////////////////////////
 854template <typename C> // C models Container
 855class move_insert_iterator
 856   : public std::iterator<std::output_iterator_tag, void, void, void, void>
 857{
 858   C* container_m;
 859   typename C::iterator pos_;
 860
 861   public:
 862   typedef C container_type;
 863
 864   explicit move_insert_iterator(C& x, typename C::iterator pos)
 865      : container_m(&x), pos_(pos)
 866   {}
 867
 868   move_insert_iterator& operator=(typename C::reference x)
 869   {
 870      pos_ = container_m->insert(pos_, ::BOOST_MOVE_NAMESPACE::move(x));
 871      ++pos_;
 872      return *this;
 873   }
 874
 875   move_insert_iterator& operator*()     { return *this; }
 876   move_insert_iterator& operator++()    { return *this; }
 877   move_insert_iterator& operator++(int) { return *this; }
 878};
 879
 880//!
 881//! <b>Returns</b>: move_insert_iterator<C>(x, it).
 882template <typename C> // C models Container
 883inline move_insert_iterator<C> move_inserter(C& x, typename C::iterator it)
 884{
 885   return move_insert_iterator<C>(x, it);
 886}
 887
 888//////////////////////////////////////////////////////////////////////////////
 889//
 890//                               move
 891//
 892//////////////////////////////////////////////////////////////////////////////
 893
 894
 895//! <b>Effects</b>: Moves elements in the range [first,last) into the range [result,result + (last -
 896//!   first)) starting from first and proceeding to last. For each non-negative integer n < (last-first),
 897//!   performs *(result + n) = ::boost::move (*(first + n)).
 898//!
 899//! <b>Effects</b>: result + (last - first).
 900//!
 901//! <b>Requires</b>: result shall not be in the range [first,last).
 902//!
 903//! <b>Complexity</b>: Exactly last - first move assignments.
 904template <typename I, // I models InputIterator
 905          typename O> // O models OutputIterator
 906O move(I f, I l, O result)
 907{
 908   while (f != l) {
 909      *result = ::BOOST_MOVE_NAMESPACE::move(*f);
 910      ++f; ++result;
 911   }
 912   return result;
 913}
 914
 915//////////////////////////////////////////////////////////////////////////////
 916//
 917//                               move_backward
 918//
 919//////////////////////////////////////////////////////////////////////////////
 920
 921//! <b>Effects</b>: Moves elements in the range [first,last) into the range
 922//!   [result - (last-first),result) starting from last - 1 and proceeding to
 923//!   first. For each positive integer n <= (last - first),
 924//!   performs *(result - n) = ::boost::move(*(last - n)).
 925//!
 926//! <b>Requires</b>: result shall not be in the range [first,last).
 927//!
 928//! <b>Returns</b>: result - (last - first).
 929//!
 930//! <b>Complexity</b>: Exactly last - first assignments.
 931template <typename I, // I models BidirectionalIterator
 932typename O> // O models BidirectionalIterator
 933O move_backward(I f, I l, O result)
 934{
 935   while (f != l) {
 936      --l; --result;
 937      *result = ::BOOST_MOVE_NAMESPACE::move(*l);
 938   }
 939   return result;
 940}
 941
 942//////////////////////////////////////////////////////////////////////////////
 943//
 944//                               uninitialized_move
 945//
 946//////////////////////////////////////////////////////////////////////////////
 947
 948//! <b>Effects</b>:
 949//!   \code
 950//!   for (; first != last; ++result, ++first)
 951//!      new (static_cast<void*>(&*result))
 952//!         typename iterator_traits<ForwardIterator>::value_type(boost::move(*first));
 953//!   \endcode
 954//!
 955//! <b>Returns</b>: result
 956template
 957   <typename I, // I models InputIterator
 958    typename F> // F models ForwardIterator
 959F uninitialized_move(I f, I l, F r
 960   /// @cond
 961   ,typename enable_if<is_movable<typename std::iterator_traits<I>::value_type> >::type* = 0
 962   /// @endcond
 963   )
 964{
 965   typedef typename std::iterator_traits<I>::value_type input_value_type;
 966   while (f != l) {
 967      ::new(static_cast<void*>(&*r)) input_value_type(BOOST_MOVE_NAMESPACE::move(*f));
 968      ++f; ++r;
 969   }
 970   return r;
 971}
 972
 973/// @cond
 974
 975template
 976   <typename I,   // I models InputIterator
 977    typename F>   // F models ForwardIterator
 978F uninitialized_move(I f, I l, F r,
 979   typename disable_if<is_movable<typename std::iterator_traits<I>::value_type> >::type* = 0)
 980{
 981   return std::uninitialized_copy(f, l, r);
 982}
 983
 984//////////////////////////////////////////////////////////////////////////////
 985//
 986//                            uninitialized_copy_or_move
 987//
 988//////////////////////////////////////////////////////////////////////////////
 989
 990namespace move_detail {
 991
 992template
 993<typename I,   // I models InputIterator
 994typename F>   // F models ForwardIterator
 995F uninitialized_move_move_iterator(I f, I l, F r,
 996                             typename enable_if< is_movable<typename I::value_type> >::type* = 0)
 997{
 998   return ::BOOST_MOVE_NAMESPACE::uninitialized_move(f, l, r);
 999}
1000
1001template
1002<typename I,   // I models InputIterator
1003typename F>   // F models ForwardIterator
1004F uninitialized_move_move_iterator(I f, I l, F r,
1005                                   typename disable_if< is_movable<typename I::value_type> >::type* = 0)
1006{
1007   return std::uninitialized_copy(f.base(), l.base(), r);
1008}
1009
1010}  //namespace move_detail {
1011
1012template
1013<typename I,   // I models InputIterator
1014typename F>   // F models ForwardIterator
1015F uninitialized_copy_or_move(I f, I l, F r,
1016                             typename enable_if< move_detail::is_move_iterator<I> >::type* = 0)
1017{
1018   return ::BOOST_MOVE_NAMESPACE::move_detail::uninitialized_move_move_iterator(f, l, r);
1019}
1020
1021//////////////////////////////////////////////////////////////////////////////
1022//
1023//                            copy_or_move
1024//
1025//////////////////////////////////////////////////////////////////////////////
1026
1027namespace move_detail {
1028
1029template
1030<typename I,   // I models InputIterator
1031typename F>   // F models ForwardIterator
1032F move_move_iterator(I f, I l, F r,
1033                             typename enable_if< is_movable<typename I::value_type> >::type* = 0)
1034{
1035   return ::BOOST_MOVE_NAMESPACE::move(f, l, r);
1036}
1037
1038template
1039<typename I,   // I models InputIterator
1040typename F>   // F models ForwardIterator
1041F move_move_iterator(I f, I l, F r,
1042                                   typename disable_if< is_movable<typename I::value_type> >::type* = 0)
1043{
1044   return std::copy(f.base(), l.base(), r);
1045}
1046
1047
1048}  //namespace move_detail {
1049
1050template
1051<typename I,   // I models InputIterator
1052typename F>   // F models ForwardIterator
1053F copy_or_move(I f, I l, F r,
1054                             typename enable_if< move_detail::is_move_iterator<I> >::type* = 0)
1055{
1056   return ::BOOST_MOVE_NAMESPACE::move_detail::move_move_iterator(f, l, r);
1057}
1058
1059/// @endcond
1060
1061//! <b>Effects</b>:
1062//!   \code
1063//!   for (; first != last; ++result, ++first)
1064//!      new (static_cast<void*>(&*result))
1065//!         typename iterator_traits<ForwardIterator>::value_type(*first);
1066//!   \endcode
1067//!
1068//! <b>Returns</b>: result
1069//!
1070//! <b>Note</b>: This function is provided because
1071//!   <i>std::uninitialized_copy</i> from some STL implementations
1072//!    is not compatible with <i>move_iterator</i>
1073template
1074<typename I,   // I models InputIterator
1075typename F>   // F models ForwardIterator
1076F uninitialized_copy_or_move(I f, I l, F r
1077   /// @cond
1078   ,typename disable_if< move_detail::is_move_iterator<I> >::type* = 0
1079   /// @endcond
1080   )
1081{
1082   return std::uninitialized_copy(f, l, r);
1083}
1084
1085//! <b>Effects</b>:
1086//!   \code
1087//!   for (; first != last; ++result, ++first)
1088//!      *result = *first;
1089//!   \endcode
1090//!
1091//! <b>Returns</b>: result
1092//!
1093//! <b>Note</b>: This function is provided because
1094//!   <i>std::uninitialized_copy</i> from some STL implementations
1095//!    is not compatible with <i>move_iterator</i>
1096template
1097<typename I,   // I models InputIterator
1098typename F>   // F models ForwardIterator
1099F copy_or_move(I f, I l, F r
1100   /// @cond
1101   ,typename disable_if< move_detail::is_move_iterator<I> >::type* = 0
1102   /// @endcond
1103   )
1104{
1105   return std::copy(f, l, r);
1106}
1107
1108//! If this trait yields to true
1109//! (<i>has_trivial_destructor_after_move &lt;T&gt;::value == true</i>)
1110//! means that if T is used as argument of a move construction/assignment,
1111//! there is no need to call T's destructor.
1112//! This optimization tipically is used to improve containers' performance.
1113//!
1114//! By default this trait is true if the type has trivial destructor,
1115//! every class should specialize this trait if it wants to improve performance
1116//! when inserted in containers.
1117template <class T>
1118struct has_trivial_destructor_after_move
1119   : public ::boost::has_trivial_destructor<T>
1120{};
1121
1122#ifndef BOOST_MOVE_DOXYGEN_INVOKED
1123
1124#ifdef BOOST_MOVE_IN_BOOST_INTERPROCESS_NAMESPACE
1125
1126#define BOOST_INTERPROCESS_ENABLE_MOVE_EMULATION(TYPE)                     BOOST_ENABLE_MOVE_EMULATION(TYPE)                 
1127#define BOOST_INTERPROCESS_MOVABLE_BUT_NOT_COPYABLE(TYPE)                  BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE)              
1128#define BOOST_INTERPROCESS_COPYABLE_AND_MOVABLE(TYPE)                      BOOST_COPYABLE_AND_MOVABLE(TYPE)                  
1129#define BOOST_INTERPROCESS_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)           BOOST_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)       
1130#define BOOST_INTERPROCESS_RV_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)     BOOST_RV_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3) 
1131#define BOOST_INTERPROCESS_RV_REF(TYPE)                                    BOOST_RV_REF(TYPE)                                
1132#define BOOST_INTERPROCESS_COPY_ASSIGN_REF(TYPE)                           BOOST_COPY_ASSIGN_REF(TYPE)                       
1133#define BOOST_INTERPROCESS_COPY_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)         BOOST_COPY_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)                
1134#define BOOST_INTERPROCESS_COPY_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)   BOOST_COPY_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)          
1135#define BOOST_INTERPROCESS_FWD_REF(TYPE)                                   BOOST_FWD_REF(TYPE)                               
1136#define BOOST_INTERPROCESS_CATCH_CONST_RLVALUE(TYPE)                       BOOST_CATCH_CONST_RLVALUE(TYPE)                   
1137
1138#endif
1139
1140#define  BOOST_MOVE_MACRO_ENABLE_MOVE_EMULATION(TYPE)                   BOOST_ENABLE_MOVE_EMULATION(TYPE)
1141#define  BOOST_MOVE_MACRO_MOVABLE_BUT_NOT_COPYABLE(TYPE)                BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE)
1142#define  BOOST_MOVE_MACRO_COPYABLE_AND_MOVABLE(TYPE)                    BOOST_COPYABLE_AND_MOVABLE(TYPE)
1143#define  BOOST_MOVE_MACRO_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)         BOOST_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)
1144#define  BOOST_MOVE_MACRO_RV_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)   BOOST_RV_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)
1145#define  BOOST_MOVE_MACRO_RV_REF(TYPE)                                  BOOST_RV_REF(TYPE)
1146#define  BOOST_MOVE_MACRO_COPY_ASSIGN_REF(TYPE)                         BOOST_COPY_ASSIGN_REF(TYPE)
1147#define  BOOST_MOVE_MACRO_COPY_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)       BOOST_COPY_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)
1148#define  BOOST_MOVE_MACRO_COPY_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3) BOOST_COPY_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)
1149#define  BOOST_MOVE_MACRO_FWD_REF(TYPE)                                 BOOST_FWD_REF(TYPE)
1150#define  BOOST_MOVE_MACRO_CATCH_CONST_RLVALUE(TYPE)                     BOOST_CATCH_CONST_RLVALUE(TYPE)
1151
1152#endif   //BOOST_MOVE_DOXYGEN_INVOKED
1153
1154INTERPROCESS_NAMESPACE_END
1155}  //namespace boost {
1156
1157#endif //#ifndef BOOST_MOVE_HPP