Debian Codegraph @

llvm-project/libcxx/include/typeindex

raw
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef _LIBCPP_TYPEINDEX
11 #define _LIBCPP_TYPEINDEX
12
13 /*
14
15 typeindex synopsis
16
17 namespace std
18 {
19
20 class type_index
21 {
22 public:
23 type_index(const type_info& rhs) noexcept;
24
25 bool operator==(const type_index& rhs) const noexcept;
26 bool operator!=(const type_index& rhs) const noexcept; // removed in C++20
27 bool operator< (const type_index& rhs) const noexcept;
28 bool operator<=(const type_index& rhs) const noexcept;
29 bool operator> (const type_index& rhs) const noexcept;
30 bool operator>=(const type_index& rhs) const noexcept;
31 strong_ordering operator<=>(const type_index& rhs) const noexcept; // C++20
32
33 size_t hash_code() const noexcept;
34 const char* name() const noexcept;
35 };
36
37 template <>
38 struct hash<type_index>
39 : public unary_function<type_index, size_t>
40 {
41 size_t operator()(type_index index) const noexcept;
42 };
43
44 } // std
45
46 */
47
48 #include <__assert> // all public C++ headers provide the assertion handler
49 #include <__config>
50 #include <__functional/unary_function.h>
51 #include <typeinfo>
52 #include <version>
53
54 // standard-mandated includes
55 #include <compare>
56
57 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
58 # pragma GCC system_header
59 #endif
60
61 _LIBCPP_BEGIN_NAMESPACE_STD
62
63 class _LIBCPP_TEMPLATE_VIS type_index
64 {
65 const type_info* __t_;
66 public:
67 _LIBCPP_INLINE_VISIBILITY
68 type_index(const type_info& __y) _NOEXCEPT : __t_(&__y) {}
69
70 _LIBCPP_INLINE_VISIBILITY
71 bool operator==(const type_index& __y) const _NOEXCEPT
72 {return *__t_ == *__y.__t_;}
73 _LIBCPP_INLINE_VISIBILITY
74 #if _LIBCPP_STD_VER <= 17
75 bool operator!=(const type_index& __y) const _NOEXCEPT
76 {return *__t_ != *__y.__t_;}
77 #endif
78 _LIBCPP_INLINE_VISIBILITY
79 bool operator< (const type_index& __y) const _NOEXCEPT
80 {return __t_->before(*__y.__t_);}
81 _LIBCPP_INLINE_VISIBILITY
82 bool operator<=(const type_index& __y) const _NOEXCEPT
83 {return !__y.__t_->before(*__t_);}
84 _LIBCPP_INLINE_VISIBILITY
85 bool operator> (const type_index& __y) const _NOEXCEPT
86 {return __y.__t_->before(*__t_);}
87 _LIBCPP_INLINE_VISIBILITY
88 bool operator>=(const type_index& __y) const _NOEXCEPT
89 {return !__t_->before(*__y.__t_);}
90 #if _LIBCPP_STD_VER > 17
91 _LIBCPP_HIDE_FROM_ABI
92 strong_ordering operator<=>(const type_index& __y) const noexcept {
93 if (*__t_ == *__y.__t_)
94 return strong_ordering::equal;
95 if (__t_->before(*__y.__t_))
96 return strong_ordering::less;
97 return strong_ordering::greater;
98 }
99 #endif
100
101 _LIBCPP_INLINE_VISIBILITY
102 size_t hash_code() const _NOEXCEPT {return __t_->hash_code();}
103 _LIBCPP_INLINE_VISIBILITY
104 const char* name() const _NOEXCEPT {return __t_->name();}
105 };
106
107 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
108
109 template <>
110 struct _LIBCPP_TEMPLATE_VIS hash<type_index>
111 : public __unary_function<type_index, size_t>
112 {
113 _LIBCPP_INLINE_VISIBILITY
114 size_t operator()(type_index __index) const _NOEXCEPT
115 {return __index.hash_code();}
116 };
117
118 _LIBCPP_END_NAMESPACE_STD
119
120 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
121 # include <iosfwd>
122 # include <new>
123 # include <utility>
124 #endif
125
126 #endif // _LIBCPP_TYPEINDEX