Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- typeindex ---------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_TYPEINDEX |
| 12 | #define _LIBCPP_TYPEINDEX |
| 13 | |
| 14 | /* |
| 15 | |
| 16 | typeindex synopsis |
| 17 | |
| 18 | namespace std |
| 19 | { |
| 20 | |
| 21 | class type_index |
| 22 | { |
| 23 | public: |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 24 | type_index(const type_info& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 26 | 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 33 | size_t hash_code() const noexcept; |
| 34 | const char* name() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | template <> |
| 38 | struct hash<type_index> |
| 39 | : public unary_function<type_index, size_t> |
| 40 | { |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 41 | size_t operator()(type_index index) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | } // std |
| 45 | |
| 46 | */ |
| 47 | |
| 48 | #include <__config> |
| 49 | #include <typeinfo> |
| 50 | #include <__functional_base> |
| 51 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 52 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 54 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | |
| 56 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 57 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 58 | class _LIBCPP_TYPE_VIS_ONLY type_index |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | { |
| 60 | const type_info* __t_; |
| 61 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 62 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 63 | type_index(const type_info& __y) _NOEXCEPT : __t_(&__y) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 65 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 66 | bool operator==(const type_index& __y) const _NOEXCEPT |
| 67 | {return *__t_ == *__y.__t_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 68 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 69 | bool operator!=(const type_index& __y) const _NOEXCEPT |
| 70 | {return *__t_ != *__y.__t_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 71 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 72 | bool operator< (const type_index& __y) const _NOEXCEPT |
| 73 | {return __t_->before(*__y.__t_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 74 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 75 | bool operator<=(const type_index& __y) const _NOEXCEPT |
| 76 | {return !__y.__t_->before(*__t_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 77 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 78 | bool operator> (const type_index& __y) const _NOEXCEPT |
| 79 | {return __y.__t_->before(*__t_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 80 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 81 | bool operator>=(const type_index& __y) const _NOEXCEPT |
| 82 | {return !__t_->before(*__y.__t_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 83 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 84 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 85 | size_t hash_code() const _NOEXCEPT {return __t_->hash_code();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 86 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 87 | const char* name() const _NOEXCEPT {return __t_->name();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 90 | template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 91 | |
| 92 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 93 | struct _LIBCPP_TYPE_VIS_ONLY hash<type_index> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 94 | : public unary_function<type_index, size_t> |
| 95 | { |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 96 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0687adc | 2011-05-28 18:57:24 +0000 | [diff] [blame] | 97 | size_t operator()(type_index __index) const _NOEXCEPT |
| 98 | {return __index.hash_code();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | _LIBCPP_END_NAMESPACE_STD |
| 102 | |
| 103 | #endif // _LIBCPP_TYPEINDEX |