Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Types | Protected Member Functions | Friends
c10::IdWrapper< ConcreteType, UnderlyingType > Class Template Reference

This template simplifies generation of simple classes that wrap an id in a typesafe way. More...

#include <IdWrapper.h>

Public Types

using underlying_type = UnderlyingType
 
using concrete_type = ConcreteType
 

Protected Member Functions

constexpr IdWrapper (underlying_type id) noexcept(noexcept(underlying_type(std::declval< underlying_type >())))
 
constexpr underlying_type underlyingId () const noexcept(noexcept(underlying_type(std::declval< underlying_type >())))
 

Friends

size_t hash_value (const concrete_type &v)
 
constexpr bool operator== (const concrete_type &lhs, const concrete_type &rhs)
 
constexpr bool operator!= (const concrete_type &lhs, const concrete_type &rhs)
 

Detailed Description

template<class ConcreteType, class UnderlyingType>
class c10::IdWrapper< ConcreteType, UnderlyingType >

This template simplifies generation of simple classes that wrap an id in a typesafe way.

Namely, you can use it to create a very lightweight type that only offers equality comparators and hashing. Example:

struct MyIdType final : IdWrapper<MyIdType, uint32_t> { constexpr explicit MyIdType(uint32_t id): IdWrapper(id) {} };

Then in the global top level namespace:

C10_DEFINE_HASH_FOR_IDWRAPPER(MyIdType);

That's it - equality operators and hash functions are automatically defined for you, given the underlying type supports it.

Definition at line 26 of file IdWrapper.h.


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