typeindex 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // -*- C++ -*-
  2. //===-------------------------- typeindex ---------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_TYPEINDEX
  11. #define _LIBCPP_TYPEINDEX
  12. /*
  13. typeindex synopsis
  14. namespace std
  15. {
  16. class type_index
  17. {
  18. public:
  19. type_index(const type_info& rhs) noexcept;
  20. bool operator==(const type_index& rhs) const noexcept;
  21. bool operator!=(const type_index& rhs) const noexcept;
  22. bool operator< (const type_index& rhs) const noexcept;
  23. bool operator<=(const type_index& rhs) const noexcept;
  24. bool operator> (const type_index& rhs) const noexcept;
  25. bool operator>=(const type_index& rhs) const noexcept;
  26. size_t hash_code() const noexcept;
  27. const char* name() const noexcept;
  28. };
  29. template <>
  30. struct hash<type_index>
  31. : public unary_function<type_index, size_t>
  32. {
  33. size_t operator()(type_index index) const noexcept;
  34. };
  35. } // std
  36. */
  37. #include <__config>
  38. #include <typeinfo>
  39. #include <__functional_base>
  40. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  41. #pragma GCC system_header
  42. #endif
  43. _LIBCPP_BEGIN_NAMESPACE_STD
  44. class _LIBCPP_TYPE_VIS_ONLY type_index
  45. {
  46. const type_info* __t_;
  47. public:
  48. _LIBCPP_INLINE_VISIBILITY
  49. type_index(const type_info& __y) _NOEXCEPT : __t_(&__y) {}
  50. _LIBCPP_INLINE_VISIBILITY
  51. bool operator==(const type_index& __y) const _NOEXCEPT
  52. {return *__t_ == *__y.__t_;}
  53. _LIBCPP_INLINE_VISIBILITY
  54. bool operator!=(const type_index& __y) const _NOEXCEPT
  55. {return *__t_ != *__y.__t_;}
  56. _LIBCPP_INLINE_VISIBILITY
  57. bool operator< (const type_index& __y) const _NOEXCEPT
  58. {return __t_->before(*__y.__t_);}
  59. _LIBCPP_INLINE_VISIBILITY
  60. bool operator<=(const type_index& __y) const _NOEXCEPT
  61. {return !__y.__t_->before(*__t_);}
  62. _LIBCPP_INLINE_VISIBILITY
  63. bool operator> (const type_index& __y) const _NOEXCEPT
  64. {return __y.__t_->before(*__t_);}
  65. _LIBCPP_INLINE_VISIBILITY
  66. bool operator>=(const type_index& __y) const _NOEXCEPT
  67. {return !__t_->before(*__y.__t_);}
  68. #if !defined(_LIBCPP_SGX_CONFIG)
  69. _LIBCPP_INLINE_VISIBILITY
  70. size_t hash_code() const _NOEXCEPT {return __t_->hash_code();}
  71. _LIBCPP_INLINE_VISIBILITY
  72. const char* name() const _NOEXCEPT {return __t_->name();}
  73. #endif // !defined(_LIBCPP_SGX_CONFIG)
  74. };
  75. #if !defined(_LIBCPP_SGX_CONFIG)
  76. template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;
  77. template <>
  78. struct _LIBCPP_TYPE_VIS_ONLY hash<type_index>
  79. : public unary_function<type_index, size_t>
  80. {
  81. _LIBCPP_INLINE_VISIBILITY
  82. size_t operator()(type_index __index) const _NOEXCEPT
  83. {return __index.hash_code();}
  84. };
  85. #endif // !defined(_LIBCPP_SGX_CONFIG)
  86. _LIBCPP_END_NAMESPACE_STD
  87. #endif // _LIBCPP_TYPEINDEX