10 #ifndef LARCOREALG_COREUTILS_SPAN_H 11 #define LARCOREALG_COREUTILS_SPAN_H 14 #include "boost/iterator/transform_iterator.hpp" 18 #include <type_traits> 27 template <
typename Cont>
35 template <
typename Cont>
43 template <
typename Cont>
47 template <
typename Cont>
51 template <
typename Cont>
59 template <
typename Cont>
67 template <
typename Cont>
71 template <
typename Cont>
128 template <
typename BIter,
typename EIter = BIter>
138 using pair_t = std::pair<begin_iterator, end_iterator>;
150 template <
typename SrcIterB,
typename SrcIterE,
typename Adaptor>
151 span(SrcIterB&& b, SrcIterE&&
e, Adaptor&& adaptor)
152 :
span(adaptor(
std::forward<SrcIterB>(b)), adaptor(
std::forward<SrcIterE>(
e)))
156 template <
typename OBIter,
typename OEIter>
181 template <
typename IterB,
typename IterE,
typename Adaptor>
182 span(IterB&& b, IterE&&
e, Adaptor&& adaptor) ->
span<
183 #if 0 // this is C++17... 184 std::invoke_result_t<Adaptor, IterB>,
185 std::invoke_result_t<Adaptor, IterE>
186 #else // ... and this is what Clang 5.0 undestands 187 decltype(adaptor(std::forward<IterB>(b))),
188 decltype(adaptor(std::forward<IterE>(
e)))
197 template <
typename BIter,
typename EIter>
204 template <
typename Cont>
211 template <
typename Cont>
226 template <
typename BIter,
typename EIter,
typename Adaptor>
229 return util::span(adaptor(begin), adaptor(end));
263 template <
typename Cont,
typename Adaptor>
272 template <
typename Cont,
typename Adaptor>
293 template <
typename BIter,
typename EIter,
typename Op>
296 auto adaptor = [&op](
auto iter) {
return boost::make_transform_iterator(iter, op); };
338 template <
typename Cont,
typename Op>
348 template <
typename Cont,
typename Op>
359 #endif // LARCOREALG_COREUTILS_SPAN_H Namespace for general, non-LArSoft-specific utilities.
bool empty() const
Returns whether the span is empty (that is, no steps between them).
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
span(begin_iterator b, end_iterator e)
Constructor: specifies the begin and end iterator.
span(SrcIterB &&b, SrcIterE &&e, Adaptor &&adaptor)
Constructor: specifies the begin and end iterator and an adapter.
static decltype(auto) get_begin(Cont &cont)
Returns the begin iterator of the specified container.
auto make_span(BIter begin, EIter end)
Creates a span from specified iterators (can use constructor instead).
std::decay_t< decltype(get_end(std::declval< Cont >()))> get_end_iterator
Type of end iterator of Cont type.
typename begin_iterator::value_type value_type
Type of values pointed by the iterators.
end_iterator end() const
Returns a copy of the end iterator.
Simple class with a begin and an end.
auto make_adapted_span(BIter begin, EIter end, Adaptor &&adaptor)
EIter end_iterator
Type of end iterator.
span(span< OBIter, OEIter > const &from)
Constructor: copies from another span (possibly with different types).
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
static decltype(auto) get_cbegin(Cont &cont)
Returns the constant begin iterator of the specified container.
static decltype(auto) get_cend(Cont &cont)
Returns the constant end iterator of the specified container.
BIter begin_iterator
Type of begin iterator.
auto make_transformed_const_span(Cont &cont, Op &&op)
std::decay_t< decltype(get_cbegin(std::declval< Cont >()))> get_cbegin_iterator
Type of constant begin iterator of Cont type.
auto make_transformed_span(BIter begin, EIter end, Op &&op)
static decltype(auto) get_end(Cont &cont)
Returns the end iterator of the specified container.
std::size_t size() const
Returns the size between begin and end, converted to std::size_t.
typename begin_iterator::reference reference
Type of reference pointed by the iterators.
begin_iterator begin() const
Returns a copy of the begin iterator.
span(IterB &&b, IterE &&e, Adaptor &&adaptor) -> span< decltype(adaptor(std::forward< IterB >(b))), decltype(adaptor(std::forward< IterE >(e))) >
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
std::pair< begin_iterator, end_iterator > pair_t
Type of iterator pair.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
second_as<> second
Type of time stored in seconds, in double precision.
Non-templated base class for span.
std::decay_t< decltype(get_begin(std::declval< Cont >()))> get_begin_iterator
Type of begin iterator of Cont type.
std::decay_t< decltype(get_cend(std::declval< Cont >()))> get_cend_iterator
Type of constant end iterator of Cont type.
auto make_const_span(Cont &cont)
Creates a span with constant iterator access from a container type.
auto make_adapted_const_span(Cont &cont, Adaptor &&adaptor)
Creates constant iteration span from specified collection via an adaptor.