llvm-project
106 строк · 3.3 Кб
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
15typeindex synopsis
16
17namespace std
18{
19
20class type_index
21{
22public:
23type_index(const type_info& rhs) noexcept;
24
25bool operator==(const type_index& rhs) const noexcept;
26bool operator!=(const type_index& rhs) const noexcept; // removed in C++20
27bool operator< (const type_index& rhs) const noexcept;
28bool operator<=(const type_index& rhs) const noexcept;
29bool operator> (const type_index& rhs) const noexcept;
30bool operator>=(const type_index& rhs) const noexcept;
31strong_ordering operator<=>(const type_index& rhs) const noexcept; // C++20
32
33size_t hash_code() const noexcept;
34const char* name() const noexcept;
35};
36
37template <>
38struct hash<type_index>
39: public unary_function<type_index, size_t>
40{
41size_t operator()(type_index index) const noexcept;
42};
43
44} // std
45
46*/
47
48#include <__config>
49#include <__functional/unary_function.h>
50#include <typeinfo>
51#include <version>
52
53// standard-mandated includes
54#include <compare>
55
56#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
57# pragma GCC system_header
58#endif
59
60_LIBCPP_BEGIN_NAMESPACE_STD
61
62class _LIBCPP_TEMPLATE_VIS type_index {
63const type_info* __t_;
64
65public:
66_LIBCPP_HIDE_FROM_ABI type_index(const type_info& __y) _NOEXCEPT : __t_(&__y) {}
67
68_LIBCPP_HIDE_FROM_ABI bool operator==(const type_index& __y) const _NOEXCEPT { return *__t_ == *__y.__t_; }
69#if _LIBCPP_STD_VER <= 17
70_LIBCPP_HIDE_FROM_ABI bool operator!=(const type_index& __y) const _NOEXCEPT { return *__t_ != *__y.__t_; }
71#endif
72_LIBCPP_HIDE_FROM_ABI bool operator<(const type_index& __y) const _NOEXCEPT { return __t_->before(*__y.__t_); }
73_LIBCPP_HIDE_FROM_ABI bool operator<=(const type_index& __y) const _NOEXCEPT { return !__y.__t_->before(*__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 !__t_->before(*__y.__t_); }
76#if _LIBCPP_STD_VER >= 20
77_LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const type_index& __y) const noexcept {
78if (*__t_ == *__y.__t_)
79return strong_ordering::equal;
80if (__t_->before(*__y.__t_))
81return strong_ordering::less;
82return strong_ordering::greater;
83}
84#endif
85
86_LIBCPP_HIDE_FROM_ABI size_t hash_code() const _NOEXCEPT { return __t_->hash_code(); }
87_LIBCPP_HIDE_FROM_ABI const char* name() const _NOEXCEPT { return __t_->name(); }
88};
89
90template <class _Tp>
91struct _LIBCPP_TEMPLATE_VIS hash;
92
93template <>
94struct _LIBCPP_TEMPLATE_VIS hash<type_index> : public __unary_function<type_index, size_t> {
95_LIBCPP_HIDE_FROM_ABI size_t operator()(type_index __index) const _NOEXCEPT { return __index.hash_code(); }
96};
97
98_LIBCPP_END_NAMESPACE_STD
99
100#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
101# include <iosfwd>
102# include <new>
103# include <utility>
104#endif
105
106#endif // _LIBCPP_TYPEINDEX
107