82 #ifndef LARDATA_UTILITIES_COLLECTIONVIEW_H 83 #define LARDATA_UTILITIES_COLLECTIONVIEW_H 90 #include <type_traits> 97 template <
typename Range>
104 template <
typename Range>
109 {
using std::cbegin;
return cbegin(range); }
111 {
using std::cend;
return cend(range); }
113 = std::decay_t<decltype(traits_t::getCBegin(std::declval<range_t>()))>;
115 = std::decay_t<decltype(traits_t::getCEnd(std::declval<range_t>()))>;
121 template <
typename BeginIter,
typename EndIter = BeginIter>
148 template <
typename BeginIter,
typename EndIter>
154 template <
typename Range>
164 template <
typename Range>
285 template <
typename Range>
318 bool empty() const noexcept {
return cbegin() == cend(); }
325 {
using std::cbegin;
return cbegin(asRange()); }
329 {
using std::cend;
return cend(asRange()); }
338 auto front() const -> decltype(auto) {
return *cbegin(); }
360 auto back() const -> decltype(auto) {
return *crbegin(); }
369 {
return cbegin()[i]; }
375 throw std::out_of_range(
376 "CollectionView index out of range: " 380 return operator[](i);
412 friend this_t details::makeCollectionView<range_t>(
range_t&&);
417 {
return static_cast<range_t const&
>(*this); }
424 template <
typename Range>
431 template <
typename BeginIter,
typename EndIter>
438 template <
typename BeginIter,
typename EndIter = BeginIter>
445 template <
typename Range>
454 #endif // LARDATA_UTILITIES_COLLECTIONVIEW_H auto at(size_type i) const -> decltype(auto)
Returns the content of the i-th element.
Provides features of a collections, from begin and end iterators.
auto makeCollectionExtremes(BeginIter const &b, EndIter const &e)
Helper to create a CollectionExtremes object from two iterators.
typename iter_traits_t::reference const_reference
end_iter_t cend() const noexcept
Returns an iterator past the end of the collection.
const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the begin of the collection.
std::decay_t< decltype(traits_t::getCBegin(std::declval< range_t >()))> begin_iterator_t
range_t collection_type
Type of collection being wrapped.
typename iter_traits_t::value_type value_type
decltype(makeCollectionView(std::declval< BeginIter >(), std::declval< EndIter >())) RangeAsCollection_t
Type of collection view owning the two range boundary iterators.
const_iterator cbegin() const noexcept
Returns an iterator to the begin of the collection.
const_iterator begin() const noexcept
Returns an iterator to the begin of the collection.
begin_iterator_t b
Stored copy of begin iterator.
typename iter_traits_t::difference_type difference_type
typename traits_t::end_iterator_t end_iter_t
Type of the end iterator.
CollectionExtremes(BeginIter b, EndIter e)
Constructor: copies the specified iterators.
end_iterator_t const & end() const
Returns the stored end iterator.
BoundaryListRangeBase< BoundaryIter > range_t
Type of the range being wrapped.
CollectionView(range_t &&range)
Constructor: steals the data from the specified range.
BeginIter begin_iterator_t
CollectionView< Range > makeCollectionView(Range &&)
Class storing a begin and a end iterator.
auto front() const -> decltype(auto)
Returns the first element in the collection.
size_type size() const noexcept
Returns the size of the collection.
range_t const & asRange() const
Returns this very object, cast back to range_t.
std::reverse_iterator< const_iterator > const_reverse_iterator
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
typename traits_t::begin_iterator_t begin_iter_t
Type of the begin iterator.
LArSoft-specific namespace.
begin_iterator_t const & begin() const
Returns the stored begin iterator.
std::iterator_traits< begin_iter_t > iter_traits_t
Type of traits of iterator.
auto back() const -> decltype(auto)
Returns the last element in the collection.
const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the begin of the collection.
static auto getCEnd(range_t const &range)
const_reverse_iterator crend() const noexcept
Returns a reverse iterator past the end of the collection.
typename iter_traits_t::pointer const_pointer
begin_iter_t const_iterator
end_iter_t end() const noexcept
Returns an iterator past the end of the collection.
const_reverse_iterator rend() const noexcept
Returns a reverse iterator past the end of the collection.
end_iterator_t e
Stored copy of end iterator.
CollectionView< Range > const & wrapCollectionIntoView(Range const &c)
Returns the specified container, wrapped in the view.
std::decay_t< decltype(traits_t::getCEnd(std::declval< range_t >()))> end_iterator_t
const_pointer data() const
static auto getCBegin(range_t const &range)
bool empty() const noexcept
Returns whether the collection is empty.