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.

join.hpp 1.8KB

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_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. namespace ranges
  25. {
  26. /// \addtogroup group-actions
  27. /// @{
  28. namespace actions
  29. {
  30. template<typename Rng>
  31. using join_action_value_t_ =
  32. meta::if_c<(bool)ranges::container<range_value_t<Rng>>, range_value_t<Rng>,
  33. std::vector<range_value_t<range_value_t<Rng>>>>;
  34. struct join_fn
  35. {
  36. public:
  37. template<typename Rng>
  38. auto operator()(Rng && rng) const -> CPP_ret(join_action_value_t_<Rng>)( //
  39. requires input_range<Rng> && input_range<range_value_t<Rng>> &&
  40. semiregular<join_action_value_t_<Rng>>)
  41. {
  42. join_action_value_t_<Rng> ret;
  43. auto last = ranges::end(rng);
  44. for(auto it = begin(rng); it != last; ++it)
  45. push_back(ret, *it);
  46. return ret;
  47. }
  48. };
  49. /// \ingroup group-actions
  50. /// \relates join_fn
  51. /// \sa action
  52. RANGES_INLINE_VARIABLE(action<join_fn>, join)
  53. } // namespace actions
  54. /// @}
  55. } // namespace ranges
  56. #endif