An aggregate: A bag of compile-time tagged types In other words, a compile-time unordered map of arbitrary types indexed by tag type.
More...
|
| template<size_t I> |
| using | tag_type = typename tuple_element_t<I, TaggedComponentsTuple>::tag_type |
| | The I'th tag type.
|
| constexpr | aggregate ()=default |
| | Default constructor.
|
| constexpr | aggregate (TaggedComponentsTuple tagged_components) |
| | Construct an aggregate that has the given components.
|
| constexpr | aggregate (const aggregate &)=default |
| | Default copy/move/assign constructors.
|
| constexpr | aggregate (aggregate &&)=default |
| constexpr aggregate & | operator= (const aggregate &)=default |
| constexpr aggregate & | operator= (aggregate &&)=default |
| template<typename Tag, typename NewComponent> |
| constexpr auto | append (NewComponent new_component) const |
| | Add a value (fluent interface):
|
| template<size_t I> |
| constexpr const auto & | get_tagged () const |
| | Fetch the I'th tagged object.
|
| template<size_t I> |
| constexpr auto & | get_tagged () |
| template<typename Tag> |
| constexpr const auto & | get_tagged () const |
| | Fetch the tagged object corresponding to the given Tag.
|
| template<typename Tag> |
| constexpr auto & | get_tagged () |
| template<size_t I> |
| constexpr const auto & | get () const |
| | Fetch the I'th value.
|
| template<size_t I> |
| constexpr auto & | get () |
| template<typename Tag> |
| constexpr const auto & | get () const |
| | Fetch the value corresponding to the given Tag.
|
| template<typename Tag> |
| constexpr auto & | get () |
| template<size_t I, typename... Args> |
| MUNDY_SUPPRESS_GPU_CALL_FROM_HOST_WARNINGS_PUSH constexpr decltype(auto) | get (Args &&... args) const |
| | Get tagged object of the given args: Perform get<I'th tag>()(args...) with syntactic sugar.
|
| template<size_t I, typename... Args> |
| constexpr decltype(auto) | get (Args &&... args) |
| template<typename Tag, typename... Args> |
| constexpr decltype(auto) | get (Args &&... args) const |
| | Get tagged object of the given args: Perform get<TAG>()(args...) with syntactic sugar.
|
| template<typename Tag, typename... Args> |
| constexpr decltype(auto) | get (Args &&... args) |
| template<typename Tag> |
| static MUNDY_SUPPRESS_GPU_CALL_FROM_HOST_WARNINGS_POP constexpr bool | has () |
| | Check if we have a value with the given Tag.
|
| static constexpr size_t | size () |
| | Get the number of components in this aggregate.
|
template<typename... TaggedComponents>
class mundy::aggregate< TaggedComponents >
They are compile-time compatable "structural types" compatable with NTTPs. Their types must be default constructible and copyable.
Construct an aggregate via a fluent interface:
.append<Tag1>(component1)
constexpr auto append(NewComponent new_component) const
Add a value (fluent interface):
Definition aggregate.hpp:666
constexpr aggregate()=default
Default constructor.
Example use cases include
- Compile-time extensible tuple:
.append<DT>(0.01)
double dt = cfg.get<DT>();
size_t it_max = cfg.get<MAX_ITERS>();
- Aggregation of accessors:
.append<CENTER>(center_accessor)
auto c = spheres.get<CENTER>(10);
auto r = spheres.get<RADIUS>(3);
auto stored_center_accessor = spheres.get<CENTER>();
- Aggregation of policies/strategies:
.append<SOLVER>(solver_policy)
solver_policies.get<SOLVER>().solve(..., solver_policies.get<PRECONDITIONER>(), ...);
- Aggregation of algorithms/functors:
.append<SORT>(SortAlgorithm{})
algs.get<SORT>(data);
auto filtered = algs.get<FILTER>(data);
- Mixed usage:
.append<POS>(pos_accessor)
.append<DT>(0.01);
agg.get<POS>(i) += agg.get<VEL>(i) * agg.get<DT>();
Tag requirements
Each Tag type must be unique within an aggregate but can otherwise be any type (including incomplete types). Indeed, to make declaring types easier, the simplest strategy is to use incomplete structs:
struct DT; struct MAX_ITERS;