move.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-present
  5. //
  6. // Use, modification and distribution is subject to the
  7. // Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // Project home: https://github.com/ericniebler/range-v3
  12. //
  13. #ifndef RANGES_V3_UTILITY_MOVE_HPP
  14. #define RANGES_V3_UTILITY_MOVE_HPP
  15. #include <type_traits>
  16. #include <meta/meta.hpp>
  17. #include <range/v3/range_fwd.hpp>
  18. #include <range/v3/utility/static_const.hpp>
  19. #include <range/v3/detail/prologue.hpp>
  20. namespace ranges
  21. {
  22. namespace aux
  23. {
  24. /// \ingroup group-utility
  25. struct move_fn : move_tag
  26. {
  27. template<typename T>
  28. constexpr meta::_t<std::remove_reference<T>> && operator()(T && t) const //
  29. noexcept
  30. {
  31. return static_cast<meta::_t<std::remove_reference<T>> &&>(t);
  32. }
  33. /// \ingroup group-utility
  34. /// \sa `move_fn`
  35. template<typename T>
  36. friend constexpr decltype(auto) operator|(T && t, move_fn move) noexcept
  37. {
  38. return move(t);
  39. }
  40. };
  41. /// \ingroup group-utility
  42. /// \sa `move_fn`
  43. RANGES_INLINE_VARIABLE(move_fn, move)
  44. /// \ingroup group-utility
  45. /// \sa `move_fn`
  46. template<typename R>
  47. using move_t =
  48. meta::if_c<std::is_reference<R>::value, meta::_t<std::remove_reference<R>> &&,
  49. detail::decay_t<R>>;
  50. } // namespace aux
  51. } // namespace ranges
  52. #include <range/v3/detail/epilogue.hpp>
  53. #endif