You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

move.hpp 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. namespace ranges
  20. {
  21. namespace aux
  22. {
  23. /// \ingroup group-utility
  24. struct move_fn : move_tag
  25. {
  26. template<typename T>
  27. constexpr auto operator()(T && t) const noexcept
  28. -> meta::_t<std::remove_reference<T>> &&
  29. {
  30. return static_cast<meta::_t<std::remove_reference<T>> &&>(t);
  31. }
  32. /// \ingroup group-utility
  33. /// \sa `move_fn`
  34. template<typename T>
  35. friend constexpr decltype(auto) operator|(T && t, move_fn move) noexcept
  36. {
  37. return move(t);
  38. }
  39. };
  40. /// \ingroup group-utility
  41. /// \sa `move_fn`
  42. RANGES_INLINE_VARIABLE(move_fn, move)
  43. /// \ingroup group-utility
  44. /// \sa `move_fn`
  45. template<typename R>
  46. using move_t =
  47. meta::if_c<std::is_reference<R>::value, meta::_t<std::remove_reference<R>> &&,
  48. detail::decay_t<R>>;
  49. } // namespace aux
  50. } // namespace ranges
  51. #endif