zip.hpp
Go to the documentation of this file.
1 // Copyright 2024 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BELUGA_VIEWS_ZIP_HPP
16 #define BELUGA_VIEWS_ZIP_HPP
17 
18 #include <tuple>
19 
20 #include <range/v3/view/zip.hpp>
21 
27 namespace beluga::views {
28 
29 namespace detail {
30 
34  template <class... Its>
35  constexpr auto operator()(const Its&... its) const //
36  noexcept((noexcept(ranges::iter_reference_t<Its>(*its)) && ...)) {
37  return ranges::common_tuple<ranges::iter_reference_t<Its>...>{*its...};
38  }
39 
41  template <class... Its>
42  constexpr auto operator()(ranges::move_tag, const Its&... its) const
43  noexcept((noexcept(ranges::iter_rvalue_reference_t<Its>(ranges::iter_move(its))) && ...)) {
44  return ranges::common_tuple<ranges::iter_rvalue_reference_t<Its>...>{ranges::iter_move(its)...};
45  }
46 
48 
51  template <class... Its>
52  constexpr auto operator()(ranges::copy_tag, Its...) const -> std::tuple<ranges::iter_value_t<Its>...> {
53  assert(false); // NOLINT(misc-static-assert)
54  return {};
55  }
56 };
57 
59 struct zip_fn {
61  template <class... Ranges>
62  constexpr auto operator()(Ranges&&... ranges) const {
63  return ranges::views::iter_zip_with(as_common_tuple_indirect_fn{}, std::forward<Ranges>(ranges)...);
64  }
65 };
66 
67 } // namespace detail
68 
70 
74 inline constexpr detail::zip_fn zip;
75 
76 } // namespace beluga::views
77 
78 #endif
beluga::views
Definition: elements.hpp:27
beluga::views::detail::zip_fn::operator()
constexpr auto operator()(Ranges &&... ranges) const
Overload that implements the zip_view algorithm.
Definition: zip.hpp:62
beluga::views::detail::as_common_tuple_indirect_fn::operator()
constexpr auto operator()(ranges::move_tag, const Its &... its) const noexcept((noexcept(ranges::iter_rvalue_reference_t< Its >(ranges::iter_move(its))) &&...))
Move overload.
Definition: zip.hpp:42
beluga::views::detail::as_common_tuple_indirect_fn::operator()
constexpr auto operator()(const Its &... its) const noexcept((noexcept(ranges::iter_reference_t< Its >(*its)) &&...))
Reference overload.
Definition: zip.hpp:35
beluga::views::detail::zip_fn
Implementation detail for a zip range adaptor object.
Definition: zip.hpp:59
std
Definition: circular_array.hpp:529
beluga::views::detail::as_common_tuple_indirect_fn::operator()
constexpr auto operator()(ranges::copy_tag, Its...) const -> std::tuple< ranges::iter_value_t< Its >... >
Copy overload.
Definition: zip.hpp:52
beluga::views::detail::as_common_tuple_indirect_fn
Utility type to adapt the zip output.
Definition: zip.hpp:32
beluga::views::zip
constexpr detail::zip_fn zip
Given N ranges, return a new range where the Mth element is a tuple of the Mth elements of all N rang...
Definition: zip.hpp:74


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53