opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
type_info_reference.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <functional>
5#include <typeinfo>
6
7namespace osc
8{
9 // A wrapper for storing a reference a `std::type_info` such that it can be used
10 // in associative lookups (e.g. `std::map`, `std::unordered_map`).
11 //
12 // This can be handy for creating arbitrary caches that use `typeid(T)`s as lookups.
14 public:
15 TypeInfoReference(const std::type_info& type_info) noexcept :
16 type_info_{&type_info}
17 {}
18
19 const std::type_info& get() const { return *type_info_; }
20
21 const char* name() const noexcept { return type_info_->name(); }
22
23 friend bool operator==(const TypeInfoReference& lhs, const TypeInfoReference& rhs) noexcept
24 {
25 return *lhs.type_info_ == *rhs.type_info_;
26 }
27
28 friend bool operator<(const TypeInfoReference& lhs, const TypeInfoReference& rhs) noexcept
29 {
30 return lhs.type_info_->before(*rhs.type_info_);
31 }
32 private:
33 const std::type_info* type_info_;
34 };
35}
36
37template<>
38struct std::hash<osc::TypeInfoReference> final {
39 size_t operator()(const osc::TypeInfoReference& ref) const noexcept
40 {
41 return ref.get().hash_code();
42 }
43};
Definition type_info_reference.h:13
TypeInfoReference(const std::type_info &type_info) noexcept
Definition type_info_reference.h:15
friend bool operator<(const TypeInfoReference &lhs, const TypeInfoReference &rhs) noexcept
Definition type_info_reference.h:28
const std::type_info & get() const
Definition type_info_reference.h:19
friend bool operator==(const TypeInfoReference &lhs, const TypeInfoReference &rhs) noexcept
Definition type_info_reference.h:23
const char * name() const noexcept
Definition type_info_reference.h:21
Definition custom_decoration_generator.h:5
constexpr U to(T &&value)
Definition conversion.h:56
size_t operator()(const osc::TypeInfoReference &ref) const noexcept
Definition type_info_reference.h:39