|
|
SizeT | operator- (OpaqueId self, OpaqueId other) |
| | Get the distance between two opaque IDs.
|
| |
|
template<class U > |
| auto | operator+ (OpaqueId id, U offset) -> std::enable_if_t< std::is_integral_v< U >, OpaqueId > |
| | Increment an opaque ID by an offset, checking against underflow.
|
| |
|
template<class U > |
| auto | operator+ (U offset, OpaqueId id) -> std::enable_if_t< std::is_integral_v< U >, OpaqueId > |
| | Increment an opaque ID by an offset (symmetric)
|
| |
|
template<class U > |
| auto | operator- (OpaqueId id, U offset) -> std::enable_if_t< std::is_integral_v< U >, OpaqueId > |
| | Decrement an opaque ID by an offset.
|
| |
|
| constexpr friend bool | operator== (OpaqueId lhs, OpaqueId rhs) noexcept |
| |
| constexpr friend bool | operator!= (OpaqueId lhs, OpaqueId rhs) noexcept |
| |
| constexpr friend bool | operator< (OpaqueId lhs, OpaqueId rhs) noexcept |
| |
| constexpr friend bool | operator> (OpaqueId lhs, OpaqueId rhs) noexcept |
| |
| constexpr friend bool | operator<= (OpaqueId lhs, OpaqueId rhs) noexcept |
| |
| constexpr friend bool | operator>= (OpaqueId lhs, OpaqueId rhs) noexcept |
| |
|
| template<class U > |
| constexpr friend auto | operator< (OpaqueId lhs, U rhs) noexcept -> std::enable_if_t< std::is_unsigned_v< U >, bool > |
| |
| template<class U > |
| constexpr friend auto | operator<= (OpaqueId lhs, U rhs) noexcept -> std::enable_if_t< std::is_unsigned_v< U >, bool > |
| |
template<
class ItemT,
class SizeT = ::celeritas::size_type>
class celeritas::OpaqueId< ItemT, SizeT >
Type-safe index for accessing an array or collection of data.
- Template Parameters
-
| ItemT | Type of an item at the index corresponding to this ID |
| SizeT | Unsigned 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 usually 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 (a "null" ID, analogous to a null pointer: it does not correspond to a valid value). A "true" ID will always compare less than a "false" ID: you can use std::partition and erase to remove invalid IDs from a vector.
See also id_cast below for checked construction of OpaqueIds from generic integer values (avoid compile-time warnings or errors from signed/truncated integers).
- Note
- Comparators are defined as inline friend functions to allow ADL-assisted conversion, including from
LdgWrapper (see Cached device loading).
- Todo:
- This interface will be changed to be more like
std::optional : size_type will become value_type (the value of a 'dereferenced' ID) and operator* or value will be used to access the integer.