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 218 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]

template<typename Element >
BaseLib::PolymorphicRandomAccessContainerView< Element >::PolymorphicRandomAccessContainerView ( PolymorphicRandomAccessContainerView< Element > const & )
delete

◆ 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
inlinenoexcept

Definition at line 252 of file ContainerTools.h.

253 {
254 return impl_->begin();
255 }
std::unique_ptr< detail::PolymorphicRandomAccessContainerViewInterface< Element > > impl_

◆ end()

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

Definition at line 257 of file ContainerTools.h.

258 {
259 return impl_->end();
260 }

◆ explicit() [1/2]

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

Definition at line 226 of file ContainerTools.h.

229 : impl_{std::make_unique<
230 detail::CovariantRandomAccessContainerView<Element, Container>>(
231 container)}
232 {
233 }

◆ explicit() [2/2]

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

Definition at line 236 of file ContainerTools.h.

239 : impl_{std::make_unique<
240 detail::CovariantRandomAccessContainerView<Element,
241 Container const>>(
242 container)}
243 {
244 }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

template<typename Element >
PolymorphicRandomAccessContainerView & BaseLib::PolymorphicRandomAccessContainerView< Element >::operator= ( PolymorphicRandomAccessContainerView< Element > const & )
delete

◆ operator[]()

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

Definition at line 264 of file ContainerTools.h.

265 {
266 return (*impl_)[n];
267 }

◆ size()

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

Definition at line 262 of file ContainerTools.h.

262{ return impl_->size(); }

Member Data Documentation

◆ impl_

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

Definition at line 272 of file ContainerTools.h.


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