OGS
BaseLib::PolymorphicRandomAccessContainerView< Element > Struct Template Reference

Detailed Description

template<typename Element>
struct BaseLib::PolymorphicRandomAccessContainerView< Element >

Provides access to the (possibly upcasted) elements of a random access container.

Example:

std::vector<std::unique_ptr<Pet>> pets;
pets.push_back(std::make_unique<Budgie>());
pets.push_back(std::make_unique<Dog>());
// Pet is derived from Animal
animals_)
{
ASSERT_EQ(2, animals_.size());
for (auto& animal : animals_)
{
animal.color = "red";
}
};
f(pets); // pass the std::vector<std::unique_ptr<Pet>> to the function
// taking the view

For further usage examples take a look into the unit tests.

Definition at line 211 of file ContainerTools.h.

#include <ContainerTools.h>

Public Member Functions

 PolymorphicRandomAccessContainerView (PolymorphicRandomAccessContainerView const &)=delete
 PolymorphicRandomAccessContainerView (PolymorphicRandomAccessContainerView &&)=default
template<typename Container>
 explicit (false) PolymorphicRandomAccessContainerView(Container &container)
template<typename Container>
 explicit (false) PolymorphicRandomAccessContainerView(Container const &container)
PolymorphicRandomAccessContainerViewoperator= (PolymorphicRandomAccessContainerView const &)=delete
PolymorphicRandomAccessContainerViewoperator= (PolymorphicRandomAccessContainerView &&)=default
detail::PolymorphicRandomAccessContainerViewIterator< Element > begin () const noexcept
detail::PolymorphicRandomAccessContainerViewIterator< Element > end () const noexcept
std::size_t size () const noexcept
Element & operator[] (std::size_t n) const

Private Attributes

std::unique_ptr< detail::PolymorphicRandomAccessContainerViewInterface< Element > > impl_

Constructor & Destructor Documentation

◆ PolymorphicRandomAccessContainerView() [1/2]

◆ PolymorphicRandomAccessContainerView() [2/2]

template<typename Element>
BaseLib::PolymorphicRandomAccessContainerView< Element >::PolymorphicRandomAccessContainerView ( PolymorphicRandomAccessContainerView< Element > && )
default

Member Function Documentation

◆ begin()

template<typename Element>
detail::PolymorphicRandomAccessContainerViewIterator< Element > BaseLib::PolymorphicRandomAccessContainerView< Element >::begin ( ) const
inlinenodiscardnoexcept

Definition at line 245 of file ContainerTools.h.

246 {
247 return impl_->begin();
248 }
std::unique_ptr< detail::PolymorphicRandomAccessContainerViewInterface< Element > > impl_

References impl_.

◆ end()

template<typename Element>
detail::PolymorphicRandomAccessContainerViewIterator< Element > BaseLib::PolymorphicRandomAccessContainerView< Element >::end ( ) const
inlinenodiscardnoexcept

Definition at line 250 of file ContainerTools.h.

251 {
252 return impl_->end();
253 }

References impl_.

◆ explicit() [1/2]

template<typename Element>
template<typename Container>
BaseLib::PolymorphicRandomAccessContainerView< Element >::explicit ( false ) &
inline

◆ explicit() [2/2]

template<typename Element>
template<typename Container>
BaseLib::PolymorphicRandomAccessContainerView< Element >::explicit ( false ) const &
inline

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ operator[]()

template<typename Element>
Element & BaseLib::PolymorphicRandomAccessContainerView< Element >::operator[] ( std::size_t n) const
inlinenodiscard

Definition at line 257 of file ContainerTools.h.

258 {
259 return (*impl_)[n];
260 }

References impl_.

◆ size()

template<typename Element>
std::size_t BaseLib::PolymorphicRandomAccessContainerView< Element >::size ( ) const
inlinenodiscardnoexcept

Definition at line 255 of file ContainerTools.h.

255{ return impl_->size(); }

References impl_.

Member Data Documentation

◆ impl_

template<typename Element>
std::unique_ptr< detail::PolymorphicRandomAccessContainerViewInterface<Element> > BaseLib::PolymorphicRandomAccessContainerView< Element >::impl_
private

Definition at line 265 of file ContainerTools.h.

Referenced by begin(), end(), explicit(), explicit(), operator[](), and size().


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