blob: 8f32ad56e065d3e21b9622bfa5361ee112dade19 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- typeindex ---------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_TYPEINDEX
12#define _LIBCPP_TYPEINDEX
13
14/*
15
16 typeindex synopsis
17
18namespace std
19{
20
21class type_index
22{
23public:
24 type_index(const type_info& rhs);
25
26 bool operator==(const type_index& rhs) const;
27 bool operator!=(const type_index& rhs) const;
28 bool operator< (const type_index& rhs) const;
29 bool operator<=(const type_index& rhs) const;
30 bool operator> (const type_index& rhs) const;
31 bool operator>=(const type_index& rhs) const;
32
33 size_t hash_code() const;
34 const char* name() const;
35};
36
37template <>
38struct hash<type_index>
39 : public unary_function<type_index, size_t>
40{
41 size_t operator()(type_index index) const;
42};
43
44} // std
45
46*/
47
48#include <__config>
49#include <typeinfo>
50#include <__functional_base>
51
52#pragma GCC system_header
53
54_LIBCPP_BEGIN_NAMESPACE_STD
55
Howard Hinnantee6ccd02010-09-23 18:58:28 +000056class _LIBCPP_VISIBLE type_index
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000057{
58 const type_info* __t_;
59public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +000060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000061 type_index(const type_info& __y) : __t_(&__y) {}
62
Howard Hinnantee6ccd02010-09-23 18:58:28 +000063 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064 bool operator==(const type_index& __y) const {return *__t_ == *__y.__t_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066 bool operator!=(const type_index& __y) const {return *__t_ != *__y.__t_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000068 bool operator< (const type_index& __y) const {return __t_->before(*__y.__t_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070 bool operator<=(const type_index& __y) const {return !__y.__t_->before(*__t_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072 bool operator> (const type_index& __y) const {return __y.__t_->before(*__t_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000074 bool operator>=(const type_index& __y) const {return !__t_->before(*__y.__t_);}
75
Howard Hinnantee6ccd02010-09-23 18:58:28 +000076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000077 size_t hash_code() const {return __t_->hash_code();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 const char* name() const {return __t_->name();}
80};
81
Howard Hinnantee6ccd02010-09-23 18:58:28 +000082template <class _Tp> struct _LIBCPP_VISIBLE hash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083
84template <>
Howard Hinnantee6ccd02010-09-23 18:58:28 +000085struct _LIBCPP_VISIBLE hash<type_index>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000086 : public unary_function<type_index, size_t>
87{
Howard Hinnantee6ccd02010-09-23 18:58:28 +000088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000089 size_t operator()(type_index __index) const {return __index.hash_code();}
90};
91
92_LIBCPP_END_NAMESPACE_STD
93
94#endif // _LIBCPP_TYPEINDEX