]>
Commit | Line | Data |
---|---|---|
bafa9791 PC |
1 | // C++0x typeindex -*- C++ -*- |
2 | ||
3 | // Copyright (C) 2010 Free Software Foundation, Inc. | |
4 | // | |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // Under Section 7 of GPL version 3, you are granted additional | |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
24 | ||
25 | /** @file include/typeindex | |
26 | * This is a Standard C++ Library header. | |
27 | */ | |
28 | ||
29 | #ifndef _GLIBCXX_TYPEINDEX | |
30 | #define _GLIBCXX_TYPEINDEX 1 | |
31 | ||
32 | #pragma GCC system_header | |
33 | ||
34 | #ifndef __GXX_EXPERIMENTAL_CXX0X__ | |
35 | # include <bits/c++0x_warning.h> | |
36 | #else | |
37 | ||
bafa9791 | 38 | #include <typeinfo> |
bafa9791 | 39 | |
53dc5044 PC |
40 | _GLIBCXX_BEGIN_NAMESPACE(std) |
41 | ||
bafa9791 PC |
42 | /** |
43 | @brief The class type_index provides a simple wrapper for type_info | |
44 | which can be used as an index type in associative containers (23.6) | |
45 | and in unordered associative containers (23.7). | |
46 | */ | |
47 | struct type_index | |
48 | { | |
49 | type_index(const type_info& __rhs) | |
50 | : _M_target(&__rhs) { } | |
51 | ||
52 | bool | |
53 | operator==(const type_index& __rhs) const | |
54 | { return *_M_target == *__rhs._M_target; } | |
55 | ||
56 | bool | |
57 | operator!=(const type_index& __rhs) const | |
58 | { return *_M_target != *__rhs._M_target; } | |
59 | ||
60 | bool | |
61 | operator<(const type_index& __rhs) const | |
62 | { return _M_target->before(*__rhs._M_target); } | |
63 | ||
64 | bool | |
65 | operator<=(const type_index& __rhs) const | |
66 | { return !__rhs._M_target->before(*_M_target); } | |
67 | ||
68 | bool | |
69 | operator>(const type_index& __rhs) const | |
70 | { return __rhs._M_target->before(*_M_target); } | |
71 | ||
72 | bool | |
73 | operator>=(const type_index& __rhs) const | |
74 | { return !_M_target->before(*__rhs._M_target); } | |
75 | ||
76 | size_t | |
77 | hash_code() const | |
78 | { return _M_target->hash_code(); } | |
79 | ||
80 | const char* | |
81 | name() const | |
82 | { return _M_target->name(); } | |
83 | ||
84 | private: | |
85 | const type_info* _M_target; | |
86 | }; | |
87 | ||
88 | template<typename _Tp> struct hash; | |
89 | ||
90 | /// std::hash specialization for type_index. | |
91 | template<> | |
92 | struct hash<type_index> | |
bafa9791 | 93 | { |
5d64ee19 PC |
94 | typedef size_t result_type; |
95 | typedef type_index argument_type; | |
96 | ||
bafa9791 PC |
97 | size_t |
98 | operator()(const type_index& __ti) const | |
99 | { return __ti.hash_code(); } | |
100 | }; | |
53dc5044 PC |
101 | |
102 | _GLIBCXX_END_NAMESPACE | |
bafa9791 PC |
103 | |
104 | #endif // __GXX_EXPERIMENTAL_CXX0X__ | |
105 | ||
106 | #endif // _GLIBCXX_TYPEINDEX |