Clementine
Classes | Public Types | Public Member Functions | List of all members
entt::view_pack< Head, Tail > Class Template Reference

View pack. More...

#include <entt.hpp>

Public Types

using entity_type = std::common_type_t< typename Head::entity_type, typename Tail::entity_type... >
 Underlying entity identifier.
 
using size_type = std::common_type_t< typename Head::size_type, typename Tail::size_type... >
 Underlying entity identifier.
 
using iterator = view_pack_iterator< typename Head::iterator >
 Input iterator type.
 
using reverse_iterator = view_pack_iterator< typename Head::reverse_iterator >
 Reversed iterator type.
 

Public Member Functions

 view_pack (const Head &first, const Tail &... last)
 Constructs a pack from a bunch of views. More...
 
iterator begin () const ENTT_NOEXCEPT
 Returns an iterator to the first entity of the pack. More...
 
iterator end () const ENTT_NOEXCEPT
 Returns an iterator that is past the last entity of the pack. More...
 
reverse_iterator rbegin () const
 Returns an iterator to the first entity of the pack. More...
 
reverse_iterator rend () const
 Returns an iterator that is past the last entity of the reversed pack. More...
 
entity_type front () const
 Returns the first entity of the pack, if any. More...
 
entity_type back () const
 Returns the last entity of the pack, if any. More...
 
iterator find (const entity_type entt) const
 Finds an entity. More...
 
bool contains (const entity_type entt) const
 Checks if a pack contains an entity. More...
 
template<typename... Comp>
decltype(auto) get ([[maybe_unused]] const entity_type entt) const
 Returns the components assigned to the given entity. More...
 
template<typename Func >
void each (Func func) const
 Iterates entities and components and applies the given function object to them. More...
 
iterable_view_pack each () const ENTT_NOEXCEPT
 Returns an iterable object to use to visit the pack. More...
 
std::tuple< Head, Tail... > pack () const ENTT_NOEXCEPT
 Returns a copy of the views stored by the pack. More...
 
template<typename... Args>
auto operator| (const basic_view< Args... > &other) const
 Appends a view to a pack. More...
 
template<typename... Pack>
auto operator| (const view_pack< Pack... > &other) const
 Appends a pack and therefore all its views to another pack. More...
 

Detailed Description

template<typename Head, typename... Tail>
class entt::view_pack< Head, Tail >

View pack.

The view pack allows users to combine multiple views into a single iterable object, while also giving them full control over which view should lead the iteration.
This class returns all and only the entities present in all views. Its intended primary use is for custom storage and views, but it can also be very convenient in everyday use.

Template Parameters
HeadType of the leading view of the pack.
TailTypes of all other views of the pack.

Constructor & Destructor Documentation

◆ view_pack()

template<typename Head, typename... Tail>
entt::view_pack< Head, Tail >::view_pack ( const Head &  first,
const Tail &...  last 
)
inline

Constructs a pack from a bunch of views.

Parameters
firstA reference to the leading view for the pack.
lastReferences to the other views to use to construct the pack.

Member Function Documentation

◆ back()

template<typename Head, typename... Tail>
entity_type entt::view_pack< Head, Tail >::back ( ) const
inline

Returns the last entity of the pack, if any.

Returns
The last entity of the pack if one exists, the null entity otherwise.

◆ begin()

template<typename Head, typename... Tail>
iterator entt::view_pack< Head, Tail >::begin ( ) const
inline

Returns an iterator to the first entity of the pack.

The returned iterator points to the first entity of the pack. If the pack is empty, the returned iterator will be equal to end().

Returns
An iterator to the first entity of the pack.

◆ contains()

template<typename Head, typename... Tail>
bool entt::view_pack< Head, Tail >::contains ( const entity_type  entt) const
inline

Checks if a pack contains an entity.

Parameters
enttA valid entity identifier.
Returns
True if the pack contains the given entity, false otherwise.

◆ each() [1/2]

template<typename Head, typename... Tail>
template<typename Func >
void entt::view_pack< Head, Tail >::each ( Func  func) const
inline

Iterates entities and components and applies the given function object to them.

The function object is invoked for each entity. It is provided with the entity itself and a set of references to non-empty components. The constness of the components is as requested.
The signature of the function must be equivalent to one of the following forms:

void(const entity_type, Type &...);
void(Type &...);
Note
Empty types aren't explicitly instantiated and therefore they are never returned during iterations.
Template Parameters
FuncType of the function object to invoke.
Parameters
funcA valid function object.

◆ each() [2/2]

template<typename Head, typename... Tail>
iterable_view_pack entt::view_pack< Head, Tail >::each ( ) const
inline

Returns an iterable object to use to visit the pack.

The iterable object returns tuples that contain the current entity and a set of references to its non-empty components. The constness of the components is as requested.

Note
Empty types aren't explicitly instantiated and therefore they are never returned during iterations.
Returns
An iterable object to use to visit the pack.

◆ end()

template<typename Head, typename... Tail>
iterator entt::view_pack< Head, Tail >::end ( ) const
inline

Returns an iterator that is past the last entity of the pack.

The returned iterator points to the entity following the last entity of the pack. Attempting to dereference the returned iterator results in undefined behavior.

Returns
An iterator to the entity following the last entity of the pack.

◆ find()

template<typename Head, typename... Tail>
iterator entt::view_pack< Head, Tail >::find ( const entity_type  entt) const
inline

Finds an entity.

Parameters
enttA valid entity identifier.
Returns
An iterator to the given entity if it's found, past the end iterator otherwise.

◆ front()

template<typename Head, typename... Tail>
entity_type entt::view_pack< Head, Tail >::front ( ) const
inline

Returns the first entity of the pack, if any.

Returns
The first entity of the pack if one exists, the null entity otherwise.

◆ get()

template<typename Head, typename... Tail>
template<typename... Comp>
decltype(auto) entt::view_pack< Head, Tail >::get ( [[maybe_unused] ] const entity_type  entt) const
inline

Returns the components assigned to the given entity.

Prefer this function instead of registry::get during iterations. It has far better performance than its counterpart.

Warning
Attempting to use an invalid component type results in a compilation error. Attempting to use an entity that doesn't belong to the pack results in undefined behavior.
Template Parameters
CompTypes of components to get.
Parameters
enttA valid entity identifier.
Returns
The components assigned to the entity.

◆ operator|() [1/2]

template<typename Head, typename... Tail>
template<typename... Args>
auto entt::view_pack< Head, Tail >::operator| ( const basic_view< Args... > &  other) const
inline

Appends a view to a pack.

Template Parameters
ArgsView template arguments.
Parameters
otherA reference to a view to append to the pack.
Returns
The extended pack.

◆ operator|() [2/2]

template<typename Head, typename... Tail>
template<typename... Pack>
auto entt::view_pack< Head, Tail >::operator| ( const view_pack< Pack... > &  other) const
inline

Appends a pack and therefore all its views to another pack.

Template Parameters
PackTypes of views of the pack to append.
Parameters
otherA reference to the pack to append.
Returns
The extended pack.

◆ pack()

template<typename Head, typename... Tail>
std::tuple<Head, Tail...> entt::view_pack< Head, Tail >::pack ( ) const
inline

Returns a copy of the views stored by the pack.

Returns
A copy of the views stored by the pack.

◆ rbegin()

template<typename Head, typename... Tail>
reverse_iterator entt::view_pack< Head, Tail >::rbegin ( ) const
inline

Returns an iterator to the first entity of the pack.

The returned iterator points to the first entity of the reversed pack. If the pack is empty, the returned iterator will be equal to rend().

Returns
An iterator to the first entity of the pack.

◆ rend()

template<typename Head, typename... Tail>
reverse_iterator entt::view_pack< Head, Tail >::rend ( ) const
inline

Returns an iterator that is past the last entity of the reversed pack.

The returned iterator points to the entity following the last entity of the reversed pack. Attempting to dereference the returned iterator results in undefined behavior.

Returns
An iterator to the entity following the last entity of the reversed pack.

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