move.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //-----------------------------------------------------------------------------
  2. // boost variant/detail/move.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2002-2003 Eric Friedman
  7. // Copyright (c) 2002 by Andrei Alexandrescu
  8. //
  9. // Use, modification and distribution are subject to the
  10. // Boost Software License, Version 1.0. (See accompanying file
  11. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  12. //
  13. // This file derivative of MoJO. Much thanks to Andrei for his initial work.
  14. // See <http://www.cuj.com/experts/2102/alexandr.htm> for information on MOJO.
  15. // Re-issued here under the Boost Software License, with permission of the original
  16. // author (Andrei Alexandrescu).
  17. #ifndef BOOST_VARIANT_DETAIL_MOVE_HPP
  18. #define BOOST_VARIANT_DETAIL_MOVE_HPP
  19. #include <iterator> // for iterator_traits
  20. #include <new> // for placement new
  21. #include "boost/config.hpp"
  22. #include "boost/detail/workaround.hpp"
  23. #include "boost/move/move.hpp"
  24. namespace boost {
  25. namespace detail { namespace variant {
  26. using boost::move;
  27. //////////////////////////////////////////////////////////////////////////
  28. // function template move_swap
  29. //
  30. // Swaps using Koenig lookup but falls back to move-swap for primitive
  31. // types and on non-conforming compilers.
  32. //
  33. #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) \
  34. || BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(2))
  35. // [Indicate that move_swap by overload is disabled...]
  36. #define BOOST_NO_MOVE_SWAP_BY_OVERLOAD
  37. // [...and provide straight swap-by-move implementation:]
  38. template <typename T>
  39. inline void move_swap(T& lhs, T& rhs)
  40. {
  41. T tmp( boost::detail::variant::move(lhs) );
  42. lhs = boost::detail::variant::move(rhs);
  43. rhs = boost::detail::variant::move(tmp);
  44. }
  45. #else// !workaround
  46. namespace detail { namespace move_swap {
  47. template <typename T>
  48. inline void swap(T& lhs, T& rhs)
  49. {
  50. T tmp( boost::detail::variant::move(lhs) );
  51. lhs = boost::detail::variant::move(rhs);
  52. rhs = boost::detail::variant::move(tmp);
  53. }
  54. }} // namespace detail::move_swap
  55. template <typename T>
  56. inline void move_swap(T& lhs, T& rhs)
  57. {
  58. using detail::move_swap::swap;
  59. swap(lhs, rhs);
  60. }
  61. #endif // workaround
  62. }} // namespace detail::variant
  63. } // namespace boost
  64. #endif // BOOST_VARIANT_DETAIL_MOVE_HPP