blob: d4d6ca96ba4d393289709e5df811aac8efe70bb3 [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:
Howard Hinnant0687adc2011-05-28 18:57:24 +000024 type_index(const type_info& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000025
Howard Hinnant0687adc2011-05-28 18:57:24 +000026 bool operator==(const type_index& rhs) const noexcept;
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 bool operator>=(const type_index& rhs) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000032
Howard Hinnant0687adc2011-05-28 18:57:24 +000033 size_t hash_code() const noexcept;
34 const char* name() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000035};
36
37template <>
38struct hash<type_index>
39 : public unary_function<type_index, size_t>
40{
Howard Hinnant0687adc2011-05-28 18:57:24 +000041 size_t operator()(type_index index) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000042};
43
44} // std
45
46*/
47
48#include <__config>
49#include <typeinfo>
50#include <__functional_base>
51
Howard Hinnant08e17472011-10-17 20:05:10 +000052#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000053#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +000054#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000055
56_LIBCPP_BEGIN_NAMESPACE_STD
57
Howard Hinnant0f678bd2013-08-12 18:38:34 +000058class _LIBCPP_TYPE_VIS_ONLY type_index
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000059{
60 const type_info* __t_;
61public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +000062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000063 type_index(const type_info& __y) _NOEXCEPT : __t_(&__y) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064
Howard Hinnantee6ccd02010-09-23 18:58:28 +000065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000066 bool operator==(const type_index& __y) const _NOEXCEPT
67 {return *__t_ == *__y.__t_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000069 bool operator!=(const type_index& __y) const _NOEXCEPT
70 {return *__t_ != *__y.__t_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000072 bool operator< (const type_index& __y) const _NOEXCEPT
73 {return __t_->before(*__y.__t_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000075 bool operator<=(const type_index& __y) const _NOEXCEPT
76 {return !__y.__t_->before(*__t_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000078 bool operator> (const type_index& __y) const _NOEXCEPT
79 {return __y.__t_->before(*__t_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000081 bool operator>=(const type_index& __y) const _NOEXCEPT
82 {return !__t_->before(*__y.__t_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083
Howard Hinnantee6ccd02010-09-23 18:58:28 +000084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000085 size_t hash_code() const _NOEXCEPT {return __t_->hash_code();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +000086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000087 const char* name() const _NOEXCEPT {return __t_->name();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000088};
89
Howard Hinnant0f678bd2013-08-12 18:38:34 +000090template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000091
92template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +000093struct _LIBCPP_TYPE_VIS_ONLY hash<type_index>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000094 : public unary_function<type_index, size_t>
95{
Howard Hinnantee6ccd02010-09-23 18:58:28 +000096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0687adc2011-05-28 18:57:24 +000097 size_t operator()(type_index __index) const _NOEXCEPT
98 {return __index.hash_code();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000099};
100
101_LIBCPP_END_NAMESPACE_STD
102
103#endif // _LIBCPP_TYPEINDEX