OGS
BaseLib::detail::CovariantRandomAccessContainerView< Element, Container > Struct Template Referencefinal

Detailed Description

template<typename Element, typename Container>
struct BaseLib::detail::CovariantRandomAccessContainerView< Element, Container >

Definition at line 145 of file ContainerTools.h.

#include <ContainerTools.h>

Inheritance diagram for BaseLib::detail::CovariantRandomAccessContainerView< Element, Container >:
[legend]
Collaboration diagram for BaseLib::detail::CovariantRandomAccessContainerView< Element, Container >:
[legend]

Public Member Functions

 CovariantRandomAccessContainerView (Container &container)
 
Element & operator[] (std::size_t index) const override
 
std::size_t size () const noexcept override
 
- Public Member Functions inherited from BaseLib::detail::PolymorphicRandomAccessContainerViewInterface< Element >
PolymorphicRandomAccessContainerViewIterator< Element > begin () const noexcept
 
PolymorphicRandomAccessContainerViewIterator< Element > end () const noexcept
 
virtual ~PolymorphicRandomAccessContainerViewInterface ()=default
 

Private Attributes

Container & container_
 

Constructor & Destructor Documentation

◆ CovariantRandomAccessContainerView()

template<typename Element , typename Container >
BaseLib::detail::CovariantRandomAccessContainerView< Element, Container >::CovariantRandomAccessContainerView ( Container & container)
inlineexplicit

Definition at line 148 of file ContainerTools.h.

149 : container_{container}
150 {
151 }

Member Function Documentation

◆ operator[]()

template<typename Element , typename Container >
Element & BaseLib::detail::CovariantRandomAccessContainerView< Element, Container >::operator[] ( std::size_t index) const
inlineoverridevirtual

Implements BaseLib::detail::PolymorphicRandomAccessContainerViewInterface< Element >.

Definition at line 153 of file ContainerTools.h.

154 {
155 if constexpr (requires {
156 typename Container::value_type::element_type;
157 })
158 {
159 static_assert(
160 std::derived_from<typename Container::value_type::element_type,
161 Element>);
162
163 return *container_[index];
164 }
165 else
166 {
167 static_assert(
168 std::derived_from<typename Container::value_type, Element>);
169
170 // this restriction is necessary because of the constness
171 // propagation of std::vector.
172 static_assert(
173 (!std::is_const_v<Container>) || std::is_const_v<Element>,
174 "If the element type is non-const, the container must be "
175 "non-const, too.");
176
177 return container_[index];
178 }
179 }

◆ size()

template<typename Element , typename Container >
std::size_t BaseLib::detail::CovariantRandomAccessContainerView< Element, Container >::size ( ) const
inlineoverridevirtualnoexcept

Member Data Documentation

◆ container_

template<typename Element , typename Container >
Container& BaseLib::detail::CovariantRandomAccessContainerView< Element, Container >::container_
private

Definition at line 184 of file ContainerTools.h.


The documentation for this struct was generated from the following file: