Meta.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef CORE_META_HPP
  2. #define CORE_META_HPP
  3. namespace Core {
  4. namespace Internal {
  5. template<typename T>
  6. struct BaseRemovePointer final {
  7. using Type = T;
  8. };
  9. template<typename T>
  10. struct BaseRemovePointer<T*> final {
  11. using Type = T;
  12. };
  13. template<typename T>
  14. struct BaseRemoveReference final {
  15. using Type = T;
  16. };
  17. template<typename T>
  18. struct BaseRemoveReference<T&> final {
  19. using Type = T;
  20. };
  21. template<typename T>
  22. struct BaseRemoveReference<T&&> final {
  23. using Type = T;
  24. };
  25. template<typename A, typename B>
  26. struct BaseIsSame final {
  27. static constexpr bool value = false;
  28. };
  29. template<typename T>
  30. struct BaseIsSame<T, T> final {
  31. static constexpr bool value = true;
  32. };
  33. template<bool C, typename A, typename B>
  34. struct BaseIf final {
  35. using Type = A;
  36. };
  37. template<typename A, typename B>
  38. struct BaseIf<false, A, B> final {
  39. using Type = B;
  40. };
  41. }
  42. template<typename T>
  43. using RemovePointer = Internal::BaseRemovePointer<T>::Type;
  44. template<typename T>
  45. using RemoveReference = Internal::BaseRemoveReference<T>::Type;
  46. template<typename T, typename U>
  47. constexpr bool IsSame = Internal::BaseIsSame<T, U>::value;
  48. template<bool C, typename A, typename B>
  49. using If = Internal::BaseIf<C, A, B>::Type;
  50. template<typename T>
  51. constexpr RemoveReference<T>&& move(T&& t) {
  52. return static_cast<RemoveReference<T>&&>(t);
  53. }
  54. template<typename T>
  55. constexpr T&& forward(RemoveReference<T>& t) {
  56. return static_cast<T&&>(t);
  57. }
  58. template<typename T>
  59. constexpr T&& forward(RemoveReference<T>&& t) {
  60. return static_cast<T&&>(t);
  61. }
  62. template<typename T>
  63. void swap(T& a, T& b) {
  64. T tmp = Core::move(a);
  65. a = Core::move(b);
  66. b = Core::move(tmp);
  67. }
  68. }
  69. #endif