copy.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_COPY_HPP
  14. #define RANGES_V3_UTILITY_COPY_HPP
  15. #include <concepts/concepts.hpp>
  16. #include <range/v3/range_fwd.hpp>
  17. #include <range/v3/utility/static_const.hpp>
  18. #include <range/v3/detail/prologue.hpp>
  19. namespace ranges
  20. {
  21. /// \addtogroup group-utility
  22. /// @{
  23. namespace aux
  24. {
  25. struct copy_fn : copy_tag
  26. {
  27. template(typename T)(
  28. requires constructible_from<detail::decay_t<T>, T>)
  29. constexpr auto operator()(T && t) const -> detail::decay_t<T>
  30. {
  31. return static_cast<T &&>(t);
  32. }
  33. /// \ingroup group-utility
  34. /// \sa `copy_fn`
  35. template<typename T>
  36. friend constexpr auto operator|(T && t, copy_fn)
  37. -> CPP_broken_friend_ret(detail::decay_t<T>)(
  38. requires constructible_from<detail::decay_t<T>, T>)
  39. {
  40. return static_cast<T &&>(t);
  41. }
  42. };
  43. /// \ingroup group-utility
  44. /// \sa `copy_fn`
  45. RANGES_INLINE_VARIABLE(copy_fn, copy)
  46. } // namespace aux
  47. /// @}
  48. } // namespace ranges
  49. #include <range/v3/detail/epilogue.hpp>
  50. #endif