join.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_ACTION_JOIN_HPP
  14. #define RANGES_V3_ACTION_JOIN_HPP
  15. #include <vector>
  16. #include <meta/meta.hpp>
  17. #include <range/v3/range_fwd.hpp>
  18. #include <range/v3/action/action.hpp>
  19. #include <range/v3/action/concepts.hpp>
  20. #include <range/v3/action/push_back.hpp>
  21. #include <range/v3/iterator/concepts.hpp>
  22. #include <range/v3/iterator/traits.hpp>
  23. #include <range/v3/utility/static_const.hpp>
  24. #include <range/v3/detail/prologue.hpp>
  25. namespace ranges
  26. {
  27. /// \addtogroup group-actions
  28. /// @{
  29. namespace actions
  30. {
  31. template<typename Rng>
  32. using join_action_value_t_ =
  33. meta::if_c<(bool)ranges::container<range_value_t<Rng>>, //
  34. range_value_t<Rng>, //
  35. std::vector<range_value_t<range_value_t<Rng>>>>;
  36. struct join_fn
  37. {
  38. template(typename Rng)(
  39. requires input_range<Rng> AND input_range<range_value_t<Rng>> AND
  40. semiregular<join_action_value_t_<Rng>>)
  41. join_action_value_t_<Rng> operator()(Rng && rng) const
  42. {
  43. join_action_value_t_<Rng> ret;
  44. auto last = ranges::end(rng);
  45. for(auto it = begin(rng); it != last; ++it)
  46. push_back(ret, *it);
  47. return ret;
  48. }
  49. };
  50. /// \relates actions::join_fn
  51. /// \sa action_closure
  52. RANGES_INLINE_VARIABLE(action_closure<join_fn>, join)
  53. } // namespace actions
  54. /// @}
  55. } // namespace ranges
  56. #include <range/v3/detail/epilogue.hpp>
  57. #endif