10 #ifndef LARDATAALG_UTILITIES_MAPPEDCONTAINER_H 11 #define LARDATAALG_UTILITIES_MAPPEDCONTAINER_H 31 template <
typename Cont>
35 template <
typename Cont,
typename =
void>
46 template <
typename T = std::
size_t>
49 return std::numeric_limits<T>::max();
125 template <
typename Cont,
typename Mapping>
147 std::remove_cv_t<Value_t> fDefValue{};
149 template <
typename Container,
typename Reference>
178 using iterator = IteratorBase<MappedContainer_t, reference>;
187 static constexpr
DataIndex_t InvalidIndex = invalidIndex<DataIndex_t>();
210 : fData(cont), fMapping(mapping), fSize(size), fDefValue(defValue)
318 decltype(
auto) operator[](
MappingIndex_t index)
const {
return map_element(index); }
338 decltype(
auto) front()
const {
return map_element(0U); }
339 decltype(
auto) front() {
return map_element(0U); }
347 decltype(
auto) back()
const {
return map_element(
size() - 1); }
348 decltype(
auto) back() {
return map_element(
size() - 1); }
414 template <
typename Cont,
typename Mapping>
432 template <
typename T>
435 T* nullTptr =
nullptr;
442 template <
typename Cont>
468 return size(container());
471 decltype(
auto) operator[](
index_type index) {
return container()[index]; }
472 decltype(
auto) operator[](
index_type index)
const {
return container()[index]; }
477 template <
typename Cont,
typename >
483 using Base_t::Base_t;
487 template <
typename Cont>
495 using Base_t::Base_t;
512 template <
typename Cont,
typename Mapping>
513 template <
typename Container,
typename Reference>
530 using value_type = std::remove_cv_t<typename Container_t::value_type>;
534 using pointer = decltype(&std::declval<reference>());
550 template <
typename OC,
typename OR>
558 template <
typename OC,
typename OR>
655 template <
typename OC,
typename OR>
658 return (fCont == other.
fCont) && (fIndex == other.
fIndex);
662 template <
typename OC,
typename OR>
665 return (fCont != other.
fCont) || (fIndex != other.
fIndex);
669 template <
typename OC,
typename OR>
670 bool operator<=(IteratorBase<OC, OR>
const&
other)
const 672 return (fCont ==
other.fCont) && (fIndex <=
other.fIndex);
676 template <
typename OC,
typename OR>
677 bool operator<(IteratorBase<OC, OR>
const&
other)
const 679 return (fCont ==
other.fCont) && (fIndex <
other.fIndex);
683 template <
typename OC,
typename OR>
686 return (fCont == other.
fCont) && (fIndex >= other.
fIndex);
690 template <
typename OC,
typename OR>
693 return (fCont == other.
fCont) && (fIndex > other.
fIndex);
702 template <
typename Cont,
typename Mapping,
typename Container,
typename Reference>
705 Reference>::difference_type
n,
716 template <
typename Cont>
727 template <
typename T>
740 template <
typename Cont>
743 util::collection_from_reference_t<util::strip_referenceness_t<Cont>>>> {};
752 template <
typename Cont,
typename Mapping>
755 return minimal_size(fData.container(), fMapping.container());
759 template <
typename Cont,
typename Mapping>
762 auto const dataIndex = map_index(index);
763 return (dataIndex == InvalidIndex) ? defaultValue() : fData[dataIndex];
767 template <
typename Cont,
typename Mapping>
770 auto const dataIndex = map_index(index);
771 return (dataIndex == InvalidIndex) ? defaultValue() : fData[dataIndex];
775 template <
typename Cont,
typename Mapping>
778 if (index >=
size()) {
779 throw std::out_of_range(
"MappedContainer::at(" +
std::to_string(index) +
782 return map_element(index);
786 template <
typename Cont,
typename Mapping>
789 if (index >=
size()) {
790 throw std::out_of_range(
"MappedContainer::at(" +
std::to_string(index) +
793 return map_element(index);
797 template <
typename Cont,
typename Mapping>
812 template <
typename Cont,
typename Mapping>
815 return fMapping[index];
819 template <
typename Cont,
typename Mapping>
822 return fMapping[index];
827 #endif // LARDATAALG_UTILITIES_MAPPEDCONTAINER_H MappedContainer< Cont, Mapping >::template IteratorBase< Container, Reference > operator+(typename MappedContainer< Cont, Mapping >::template IteratorBase< Container, Reference >::difference_type n, typename MappedContainer< Cont, Mapping >::template IteratorBase< Container, Reference > const &it)
typename Cont::type DataContainer_t
auto mapContainer(Cont cont, Mapping mapping)
Returns a container-like object mapping the content of cont.
Iterator_t & operator=(IteratorBase< OC, OR > const &from)
Assignment from a different container type.
Namespace for general, non-LArSoft-specific utilities.
typename Storage_t::value_type Value_t
Type of contained value.
IteratorBase(IteratorBase< OC, OR > const &from)
Copy constructor: from a different container type.
std::ptrdiff_t difference_type
MappingIndex_t fIndex
Current index in container.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::iterator iterator
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
A meta-container providing transparent mapping on top of another.
bool operator==(IteratorBase< OC, OR > const &other) const
Returns whether this iterator is not equal to other.
Mapping Mapping_t
Type of the mapping object.
Iterator_t & operator+=(difference_type n)
Increments this iterator by n steps and returns it incremented.
Iterator_t & operator--()
Decrements this iterator and returns it decremented.
const_reference defaultValue() const
Returns the nominal size of the container (after mapping).
IteratorBase< MappedContainer_t, reference > iterator
size_type minimal_size() const
Returns the minimum size to include all mapped values.
std::size_t MappingIndex_t
Type of the index passed to the mapping.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::size_type size_type
reference operator*() const
Returns a member of the mapped item the iterator currently points to.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::reference reference
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::const_reference const_reference
reference operator[](difference_type n) const
ContainerStorageBase(Container_t const &cont)
const_iterator cbegin() const
Returns a constant iterator to the first mapped element.
Iterator_t & operator-=(difference_type n)
Decrements this iterator by n steps and returns it decremented.
util::with_const_as_t< typename Storage_t::reference, util::collection_value_access_t< DataContainer_t >> reference
size_type size() const
Returns the nominal size of the container (after mapping).
std::remove_cv_t< typename Container_t::value_type > value_type
Iterator_t operator++(int)
Increments this iterator and returns its old value.
Iterator_t operator--(int)
Decrements this iterator and returns its old value.
const_iterator begin() const
Returns a constant iterator to the first mapped element.
MappedContainer(DataContainer_t const &cont, Mapping_t const &mapping, size_type size)
Constructor: acquires data and mapping.
static constexpr T invalidIndex()
Non-template base class for MappedContainer.
T const & const_reference
typename Container_t::size_type size_type
void setDefaultValue(value_type defValue)
IteratorBase(Container_t &cont, MappingIndex_t index)
Constructor: iterator pointing to element index of cont.
ContainerStorageBase(Container_t &&cont)
typename Traits_t::size_type index_type
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
std::ptrdiff_t difference_type
difference_type operator-(Iterator_t &other) const
Returns the number of steps this iterator is ahead of other.
Iterator_t operator+(difference_type n) const
Returns an iterator pointing n steps ahead of this one.
iterator end()
Returns an iterator past the last mapped element.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
Iterator_t & operator++()
Increments this iterator and returns its old value.
decltype(auto) map_index(MappingIndex_t index) const
Returns the index in the original data which is mapped to index.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::difference_type difference_type
typename Container_t::difference_type difference_type
bool operator>=(IteratorBase< OC, OR > const &other) const
Returns whether this iterator is ahead of or equal to other.
phot::IPhotonLibrary::T0s_t DataContainer_t
Type of the original container.
const_iterator cend() const
Returns a constant iterator past the last mapped element.
typename Traits_t::reference reference
typename Traits_t::const_reference const_reference
decltype(auto) map_element(MappingIndex_t index)
Returns the value mapped to the specified index.
bool operator!=(IteratorBase< OC, OR > const &other) const
Returns whether this iterator is not equal to other.
decltype(&std::declval< reference >()) pointer
IteratorBase< MappedContainer_t const, const_reference > const_iterator
iterator begin()
Returns an iterator to the first mapped element.
MappingStorage_t fMapping
Mapping of stored data into final one.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::value_type value_type
MappedContainer(DataContainer_t const &cont, Mapping_t const &mapping)
Constructor: acquires data and mapping.
const_iterator end() const
Returns a constant iterator past the last mapped element.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::const_iterator const_iterator
typename Traits_t::size_type size_type
util::collection_value_t< Mapping_t > DataIndex_t
Type of the index passed to the original container.
size_type max_size() const
Returns the size of the largest possible container of this type.
Container_t * fCont
Pointer to the container.
bool empty() const
Returns whether the container has no elements.
std::input_iterator_tag iterator_category
Iterator_t operator-(difference_type n) const
Returns an iterator pointing n steps behind this one.
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Storage_t fData
Data to be mapped.
decltype(auto) at(MappingIndex_t index) const
Returns the content corresponding to the specified index.
reference defaultValue()
Returns the default value for elements with no original content.
MappedContainer(DataContainer_t const &cont, Mapping_t const &mapping, size_type size, value_type defValue)
Constructor: acquires data, mapping and a default value.
typename Storage_t::const_reference const_reference
QuadExpr operator*(double v, const QuadExpr &e)
bool operator>(IteratorBase< OC, OR > const &other) const
Returns whether this iterator is strictly ahead of other.
typename Traits_t::value_type value_type
reference operator->() const
Returns a member of the mapped item the iterator currently points to.
typename Traits_t::difference_type difference_type
std::size_t Size_t
Type for describing container size.