policy.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef ENTT_META_POLICY_HPP
  2. #define ENTT_META_POLICY_HPP
  3. #include <type_traits>
  4. namespace entt {
  5. /*! @brief Empty class type used to request the _as ref_ policy. */
  6. struct as_ref_t final {
  7. /**
  8. * @cond TURN_OFF_DOXYGEN
  9. * Internal details not to be documented.
  10. */
  11. template<typename Type>
  12. static constexpr bool value = std::is_reference_v<Type> && !std::is_const_v<std::remove_reference_t<Type>>;
  13. /**
  14. * Internal details not to be documented.
  15. * @endcond
  16. */
  17. };
  18. /*! @brief Empty class type used to request the _as cref_ policy. */
  19. struct as_cref_t final {
  20. /**
  21. * @cond TURN_OFF_DOXYGEN
  22. * Internal details not to be documented.
  23. */
  24. template<typename Type>
  25. static constexpr bool value = std::is_reference_v<Type>;
  26. /**
  27. * Internal details not to be documented.
  28. * @endcond
  29. */
  30. };
  31. /*! @brief Empty class type used to request the _as-is_ policy. */
  32. struct as_is_t final {
  33. /**
  34. * @cond TURN_OFF_DOXYGEN
  35. * Internal details not to be documented.
  36. */
  37. template<typename>
  38. static constexpr bool value = true;
  39. /**
  40. * Internal details not to be documented.
  41. * @endcond
  42. */
  43. };
  44. /*! @brief Empty class type used to request the _as void_ policy. */
  45. struct as_void_t final {
  46. /**
  47. * @cond TURN_OFF_DOXYGEN
  48. * Internal details not to be documented.
  49. */
  50. template<typename>
  51. static constexpr bool value = true;
  52. /**
  53. * Internal details not to be documented.
  54. * @endcond
  55. */
  56. };
  57. /**
  58. * @brief Provides the member constant `value` to true if a type also is a meta
  59. * policy, false otherwise.
  60. * @tparam Type Type to check.
  61. */
  62. template<typename Type>
  63. struct is_meta_policy
  64. : std::bool_constant<std::is_same_v<Type, as_ref_t> || std::is_same_v<Type, as_cref_t> || std::is_same_v<Type, as_is_t> || std::is_same_v<Type, as_void_t>> {};
  65. /**
  66. * @brief Helper variable template.
  67. * @tparam Type Type to check.
  68. */
  69. template<typename Type>
  70. inline constexpr bool is_meta_policy_v = is_meta_policy<Type>::value;
  71. } // namespace entt
  72. #endif