Celeritas  0.5.0-86+4a8eea4
Classes | Typedefs | Functions
VariantUtils.hh File Reference

Host-only utilities for use with std::variant. More...

#include <type_traits>
#include <utility>
#include "corecel/Assert.hh"
#include "detail/VariantUtilsImpl.hh"
This graph shows which files directly or indirectly include this file:

Classes

struct  celeritas::Overload< Ts >
 Helper class for dispatching type-specific lambdas. More...
 
class  celeritas::ContainerVisitor< T, U >
 Visit a container's element by calling "visit" on the corresponding index. More...
 

Typedefs

template<class E , template< E > class ETraits>
using celeritas::EnumVariant = typename detail::EnumVariantImpl< E, ETraits >::type
 Define a variant that contains all the classes mapped by an enum+traits. More...
 

Functions

template<class... Ts>
 celeritas::Overload (Ts &&...) -> Overload< Ts... >
 
template<class T , class F >
detail::ReturnAsImpl< T, F > celeritas::return_as (F &&func)
 Create a wrapper functor for unifying the return type. More...
 
template<class T >
 celeritas::ContainerVisitor (T &&) -> ContainerVisitor< T >
 

Detailed Description

Host-only utilities for use with std::variant.

Typedef Documentation

◆ EnumVariant

template<class E , template< E > class ETraits>
using celeritas::EnumVariant = typedef typename detail::EnumVariantImpl<E, ETraits>::type

Define a variant that contains all the classes mapped by an enum+traits.

For example:

using VariantSurface = EnumVariant<SurfaceType, SurfaceTypeTraits>;
EnumVariant< SurfaceType, SurfaceTypeTraits > VariantSurface
std::variant class of all surfaces.
Definition: VariantSurface.hh:23

is equivalent to:

using VariantSurface = std::variant<PlaneX, PlaneY, ..., GeneralQuadric>;
See also
EnumClassUtils.hh

Function Documentation

◆ return_as()

template<class T , class F >
detail::ReturnAsImpl<T, F> celeritas::return_as ( F &&  func)

Create a wrapper functor for unifying the return type.

This provides a unified return type T (usually a variant) that can be implicitly constructed from all return types of a functor F that operates on a generic type U . The class is necessary because std::visit requires all return types to be the same.

Example:

std::visit(return_as<VariantTransform>(Translate{{1,2,3}}), value);