Celeritas 0.7+4171d81
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
OpaqueId.hh File Reference
#include <cstddef>
#include <type_traits>
#include "Assert.hh"
#include "Macros.hh"
#include "Types.hh"
#include <functional>
#include <ostream>

Classes

struct  celeritas::nullid_t
 Tag type used for nullid. More...
 
class  celeritas::OpaqueId< TagT, IndexT >
 Type-safe "optional" index for accessing an array or collection of data. More...
 
struct  celeritas::MakeSize< OpaqueId< I, V > >
 Specialize size type for opaque IDs. More...
 
struct  celeritas::detail::IsOpaqueId< T >
 Template matching to determine if T is an OpaqueId. More...
 
struct  celeritas::detail::IsOpaqueId< OpaqueId< I, V > >
 

Macros

#define CELER_DEFINE_OPAQUEID_CMP(TOKEN)
 
#define CELER_DEFINE_OPAQUEID_CMP(TOKEN)
 

Functions

template<class I >
void celeritas::detail::stream_opaqueid_impl (std::ostream &, I, I)
 
template<class T , class J >
T celeritas::detail::id_cast_impl (J value) noexcept(! 0)
 Safely cast from one integer T to another J, avoiding the sentinel value.
 
template<class V >
void celeritas::detail::stream_opaqueid_impl (std::ostream &os, V v, V nullint)
 
template<>
void celeritas::detail::stream_opaqueid_impl (std::ostream &os, unsigned char v, unsigned char nullid)
 
template<class IdT , class J >
auto celeritas::id_cast (J value) noexcept(! 0) -> std::enable_if_t< is_opaque_id_v< IdT > &&std::is_integral_v< J >, IdT >
 Safely create an OpaqueId from an integer of any type.
 
template<class I , class T >
constexpr T constceleritas::ldg_data (OpaqueId< I, T > const *ptr) noexcept
 Support loading OpaqueId via GPU cache.
 

Variables

template<class I >
constexpr I celeritas::detail::nullid_value {static_cast<I>(-1)}
 Sentinel value for an unassigned opaque ID.
 
constexpr nullid_t celeritas::nullid {0}
 Tag instance used to instantiate and compare to a null OpaqueId.
 
template<class T >
constexpr bool celeritas::is_opaque_id_v = detail::IsOpaqueId<std::remove_cv_t<T>>::value
 True if T is an OpaqueID.
 

Macro Definition Documentation

◆ CELER_DEFINE_OPAQUEID_CMP [1/2]

#define CELER_DEFINE_OPAQUEID_CMP (   TOKEN)
Value:
CELER_CEF friend bool operator TOKEN(OpaqueId lhs, OpaqueId rhs) noexcept \
{ \
return *lhs TOKEN * rhs; \
}
#define CELER_CEF
Decorate a function that works on both host and device, with and without NVCC.
Definition Macros.hh:85

◆ CELER_DEFINE_OPAQUEID_CMP [2/2]

#define CELER_DEFINE_OPAQUEID_CMP (   TOKEN)
Value:
template<class J> \
CELER_CEF friend auto operator TOKEN(OpaqueId lhs, J rhs) noexcept \
-> std::enable_if_t<std::is_unsigned_v<J>, bool> \
{ \
return lhs && (static_cast<J>(*lhs) TOKEN rhs); \
}

Function Documentation

◆ id_cast()

template<class IdT , class J >
auto celeritas::id_cast ( J  value) -> std::enable_if_t<is_opaque_id_v<IdT> && std::is_integral_v<J>, IdT>
inlinenoexcept

Safely create an OpaqueId from an integer of any type.

This asserts that the integer is in the valid range of the target ID type, and casts to it.

Note
The value cannot be the underlying "null" value; i.e. static_cast<FooId>(*FooId{}) will not work.