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

Classes

class  celeritas::OpaqueId< ItemT, SizeT >
 Type-safe index for accessing an array or collection of data. More...
 
struct  celeritas::LdgTraits< OpaqueId< I, T >, void >
 

Macros

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

Functions

template<class IdT , class U >
auto celeritas::id_cast (U value) noexcept(! 0) -> std::enable_if_t< is_opaque_id_v< IdT > &&std::is_integral_v< U >, IdT >
 Safely create an OpaqueId from an integer of any type.
 
template<class V , class S >
std::ostream & celeritas::operator<< (std::ostream &os, OpaqueId< V, S > const &v)
 Output an opaque ID's value or a placeholder if unavailable.
 

Variables

template<class T >
constexpr T celeritas::nullid_value {static_cast<T>(-1)}
 Sentinel value for an unassigned opaque ID.
 
template<class T >
constexpr bool celeritas::is_opaque_id_v = detail::IsOpaqueId<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.unchecked_get() TOKEN rhs.unchecked_get(); \
}
#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 U> \
CELER_CEF friend auto operator TOKEN(OpaqueId lhs, U rhs) noexcept \
-> std::enable_if_t<std::is_unsigned_v<U>, bool> \
{ \
return lhs && (static_cast<U>(lhs.unchecked_get()) TOKEN rhs); \
}

Function Documentation

◆ id_cast()

template<class IdT , class U >
auto celeritas::id_cast ( value) -> std::enable_if_t<is_opaque_id_v<IdT> && std::is_integral_v<U>, 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{}.unchecked_get()) will not work.