Celeritas  0.5.0-56+6b053cd
Public Member Functions | List of all members
celeritas::OpaqueId< ValueT, SizeT > Class Template Reference

Type-safe index for accessing an array or collection of data. More...

#include <OpaqueId.hh>

Public Types

Type aliases
using value_type = ValueT
 
using size_type = SizeT
 

Public Member Functions

constexpr OpaqueId ()
 Default to invalid state.
 
constexpr OpaqueId (size_type index)
 Construct explicitly with stored value.
 
constexpr operator bool () const
 Whether this ID is in a valid (assigned) state.
 
OpaqueIdoperator++ ()
 Pre-increment of the ID.
 
OpaqueId operator++ (int)
 Post-increment of the ID.
 
OpaqueIdoperator-- ()
 Pre-decrement of the ID.
 
OpaqueId operator-- (int)
 Post-decrement of the ID.
 
size_type get () const
 Get the ID's value.
 
constexpr size_type unchecked_get () const
 Get the value without checking for validity (atypical)
 
constexpr size_type const * data () const
 Access the underlying data for more efficient loading from memory.
 

Detailed Description

template<class ValueT, class SizeT = ::celeritas::size_type>
class celeritas::OpaqueId< ValueT, SizeT >

Type-safe index for accessing an array or collection of data.

Template Parameters
ValueTType of each item in an array
SizeTUnsigned integer index

It's common for classes and functions to take multiple indices, especially for O(1) indexing for performance. By annotating these values with a type, we give them semantic meaning, and we gain compile-time type safety.

If this class is used for indexing into an array, then ValueT argument should be the value type of the array: Foo operator[](OpaqueId<Foo>)

An OpaqueId object evaluates to true if it has a value, or false if it does not (i.e. it has an "invalid" value).

See also id_cast below for checked construction of OpaqueIds from generic integer values (avoid compile-time warnings or errors from signed/truncated integers).


The documentation for this class was generated from the following file: