Mundy: Multibody Nonlocal Dynamics Version of the Day
Loading...
Searching...
No Matches
mundy::aggregate< TaggedComponents > Class Template Reference

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...

#include <aggregate.hpp>

Public Types

using TaggedComponentsTuple = tuple<TaggedComponents...>

Public Attributes

Private members (no touch)
TaggedComponentsTuple tagged_components_

Constructors

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 aggregateoperator= (const aggregate &)=default
constexpr aggregateoperator= (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.

Detailed Description

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:

auto agg = aggregate()
.append<Tag1>(component1)
.append<Tag2>(component2);
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

  1. Compile-time extensible tuple:
    auto cfg = aggregate()
    .append<DT>(0.01)
    double dt = cfg.get<DT>();
    size_t it_max = cfg.get<MAX_ITERS>();
    // double dt = cfg.get<DT>(0); // error: DT is not callable
  2. Aggregation of accessors:
    auto spheres = aggregate()
    .append<CENTER>(center_accessor)
    .append<RADIUS>(radius_accessor);
    auto c = spheres.get<CENTER>(10);
    auto r = spheres.get<RADIUS>(3);
    auto stored_center_accessor = spheres.get<CENTER>();
  3. Aggregation of policies/strategies:
    auto solver_policies = aggregate()
    .append<SOLVER>(solver_policy)
    .append<PRECONDITIONER>(preconditioner_policy);
    solver_policies.get<SOLVER>().solve(..., solver_policies.get<PRECONDITIONER>(), ...);
  4. Aggregation of algorithms/functors:
    auto algs = aggregate()
    .append<SORT>(SortAlgorithm{})
    .append<FILTER>(FilterAlgorithm{});
    algs.get<SORT>(data);
    auto filtered = algs.get<FILTER>(data);
  5. Mixed usage:
    auto agg = aggregate()
    .append<POS>(pos_accessor)
    .append<VEL>(vel_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;

Member Typedef Documentation

◆ TaggedComponentsTuple

template<typename... TaggedComponents>
using mundy::aggregate< TaggedComponents >::TaggedComponentsTuple = tuple<TaggedComponents...>

◆ tag_type

template<typename... TaggedComponents>
template<size_t I>
using mundy::aggregate< TaggedComponents >::tag_type = typename tuple_element_t<I, TaggedComponentsTuple>::tag_type

Constructor & Destructor Documentation

◆ aggregate() [1/4]

template<typename... TaggedComponents>
mundy::aggregate< TaggedComponents >::aggregate ( )
constexprdefault

◆ aggregate() [2/4]

template<typename... TaggedComponents>
mundy::aggregate< TaggedComponents >::aggregate ( TaggedComponentsTuple tagged_components)
inlineconstexpr

◆ aggregate() [3/4]

template<typename... TaggedComponents>
mundy::aggregate< TaggedComponents >::aggregate ( const aggregate< TaggedComponents > & )
constexprdefault

◆ aggregate() [4/4]

template<typename... TaggedComponents>
mundy::aggregate< TaggedComponents >::aggregate ( aggregate< TaggedComponents > && )
constexprdefault

Member Function Documentation

◆ operator=() [1/2]

template<typename... TaggedComponents>
aggregate & mundy::aggregate< TaggedComponents >::operator= ( const aggregate< TaggedComponents > & )
constexprdefault

◆ operator=() [2/2]

template<typename... TaggedComponents>
aggregate & mundy::aggregate< TaggedComponents >::operator= ( aggregate< TaggedComponents > && )
constexprdefault

◆ append()

template<typename... TaggedComponents>
template<typename Tag, typename NewComponent>
auto mundy::aggregate< TaggedComponents >::append ( NewComponent new_component) const
inlineconstexpr

◆ get_tagged() [1/4]

template<typename... TaggedComponents>
template<size_t I>
const auto & mundy::aggregate< TaggedComponents >::get_tagged ( ) const
inlineconstexpr

◆ get_tagged() [2/4]

template<typename... TaggedComponents>
template<size_t I>
auto & mundy::aggregate< TaggedComponents >::get_tagged ( )
inlineconstexpr

◆ get_tagged() [3/4]

template<typename... TaggedComponents>
template<typename Tag>
const auto & mundy::aggregate< TaggedComponents >::get_tagged ( ) const
inlineconstexpr

◆ get_tagged() [4/4]

template<typename... TaggedComponents>
template<typename Tag>
auto & mundy::aggregate< TaggedComponents >::get_tagged ( )
inlineconstexpr

◆ get() [1/8]

template<typename... TaggedComponents>
template<size_t I>
const auto & mundy::aggregate< TaggedComponents >::get ( ) const
inlineconstexpr

◆ get() [2/8]

template<typename... TaggedComponents>
template<size_t I>
auto & mundy::aggregate< TaggedComponents >::get ( )
inlineconstexpr

◆ get() [3/8]

template<typename... TaggedComponents>
template<typename Tag>
const auto & mundy::aggregate< TaggedComponents >::get ( ) const
inlineconstexpr

◆ get() [4/8]

template<typename... TaggedComponents>
template<typename Tag>
auto & mundy::aggregate< TaggedComponents >::get ( )
inlineconstexpr

◆ get() [5/8]

template<typename... TaggedComponents>
template<size_t I, typename... Args>
MUNDY_SUPPRESS_GPU_CALL_FROM_HOST_WARNINGS_PUSH constexpr decltype(auto) mundy::aggregate< TaggedComponents >::get ( Args &&... args) const
inlineconstexpr

◆ get() [6/8]

template<typename... TaggedComponents>
template<size_t I, typename... Args>
decltype(auto) mundy::aggregate< TaggedComponents >::get ( Args &&... args)
inlineconstexpr

◆ get() [7/8]

template<typename... TaggedComponents>
template<typename Tag, typename... Args>
decltype(auto) mundy::aggregate< TaggedComponents >::get ( Args &&... args) const
inlineconstexpr

◆ get() [8/8]

template<typename... TaggedComponents>
template<typename Tag, typename... Args>
decltype(auto) mundy::aggregate< TaggedComponents >::get ( Args &&... args)
inlineconstexpr

◆ has()

template<typename... TaggedComponents>
template<typename Tag>
MUNDY_SUPPRESS_GPU_CALL_FROM_HOST_WARNINGS_POP constexpr bool mundy::aggregate< TaggedComponents >::has ( )
inlinestaticconstexpr

◆ size()

template<typename... TaggedComponents>
constexpr size_t mundy::aggregate< TaggedComponents >::size ( )
inlinestaticconstexpr

Member Data Documentation

◆ tagged_components_

template<typename... TaggedComponents>
TaggedComponentsTuple mundy::aggregate< TaggedComponents >::tagged_components_