2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_TYPEINDEX
11 #define _LIBCPP_TYPEINDEX
23 type_index(const type_info& rhs) noexcept;
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
33 size_t hash_code() const noexcept;
34 const char* name() const noexcept;
38 struct hash<type_index>
39 : public unary_function<type_index, size_t>
41 size_t operator()(type_index index) const noexcept;
48 #include <__assert> // all public C++ headers provide the assertion handler
50 #include <__functional/unary_function.h>
54 // standard-mandated includes
57 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
58 # pragma GCC system_header
61 _LIBCPP_BEGIN_NAMESPACE_STD
63 class _LIBCPP_TEMPLATE_VIS type_index {
64 const type_info* __t_;
67 _LIBCPP_HIDE_FROM_ABI type_index(const type_info& __y) _NOEXCEPT : __t_(&__y) {}
69 _LIBCPP_HIDE_FROM_ABI bool operator==(const type_index& __y) const _NOEXCEPT { return *__t_ == *__y.__t_; }
70 #if _LIBCPP_STD_VER <= 17
71 _LIBCPP_HIDE_FROM_ABI bool operator!=(const type_index& __y) const _NOEXCEPT { return *__t_ != *__y.__t_; }
73 _LIBCPP_HIDE_FROM_ABI bool operator<(const type_index& __y) const _NOEXCEPT { return __t_->before(*__y.__t_); }
74 _LIBCPP_HIDE_FROM_ABI bool operator<=(const type_index& __y) const _NOEXCEPT { return !__y.__t_->before(*__t_); }
75 _LIBCPP_HIDE_FROM_ABI bool operator>(const type_index& __y) const _NOEXCEPT { return __y.__t_->before(*__t_); }
76 _LIBCPP_HIDE_FROM_ABI bool operator>=(const type_index& __y) const _NOEXCEPT { return !__t_->before(*__y.__t_); }
77 #if _LIBCPP_STD_VER >= 20
78 _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const type_index& __y) const noexcept {
79 if (*__t_ == *__y.__t_)
80 return strong_ordering::equal;
81 if (__t_->before(*__y.__t_))
82 return strong_ordering::less;
83 return strong_ordering::greater;
87 _LIBCPP_HIDE_FROM_ABI size_t hash_code() const _NOEXCEPT { return __t_->hash_code(); }
88 _LIBCPP_HIDE_FROM_ABI const char* name() const _NOEXCEPT { return __t_->name(); }
92 struct _LIBCPP_TEMPLATE_VIS hash;
95 struct _LIBCPP_TEMPLATE_VIS hash<type_index> : public __unary_function<type_index, size_t> {
96 _LIBCPP_HIDE_FROM_ABI size_t operator()(type_index __index) const _NOEXCEPT { return __index.hash_code(); }
99 _LIBCPP_END_NAMESPACE_STD
101 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
107 #endif // _LIBCPP_TYPEINDEX