classify.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * Copyright (c) 2020-2025 Andrey Semashev
  7. */
  8. /*!
  9. * \file atomic/detail/classify.hpp
  10. *
  11. * This header contains type traits for type classification.
  12. */
  13. #ifndef BOOST_ATOMIC_DETAIL_CLASSIFY_HPP_INCLUDED_
  14. #define BOOST_ATOMIC_DETAIL_CLASSIFY_HPP_INCLUDED_
  15. #include <type_traits>
  16. #include <boost/atomic/detail/config.hpp>
  17. #include <boost/atomic/detail/type_traits/is_integral.hpp>
  18. #include <boost/atomic/detail/type_traits/is_floating_point.hpp>
  19. #include <boost/atomic/detail/header.hpp>
  20. #ifdef BOOST_HAS_PRAGMA_ONCE
  21. #pragma once
  22. #endif
  23. namespace boost {
  24. namespace atomics {
  25. namespace detail {
  26. template< typename T, bool IsFunction = std::is_function< T >::value >
  27. struct classify_pointer
  28. {
  29. using type = void*;
  30. };
  31. template< typename T >
  32. struct classify_pointer< T, true >
  33. {
  34. using type = void;
  35. };
  36. template<
  37. typename T,
  38. bool IsInt = atomics::detail::is_integral< T >::value,
  39. bool IsFloat = atomics::detail::is_floating_point< T >::value,
  40. bool IsEnum = std::is_enum< T >::value
  41. >
  42. struct classify
  43. {
  44. using type = void;
  45. };
  46. template< typename T >
  47. struct classify< T, true, false, false > { using type = int; };
  48. #if !defined(BOOST_ATOMIC_NO_FLOATING_POINT)
  49. template< typename T >
  50. struct classify< T, false, true, false > { using type = float; };
  51. #endif
  52. template< typename T >
  53. struct classify< T, false, false, true > { using type = const int; };
  54. template< typename T >
  55. struct classify< T*, false, false, false > { using type = typename classify_pointer< T >::type; };
  56. template< >
  57. struct classify< void*, false, false, false > { using type = void; };
  58. template< >
  59. struct classify< const void*, false, false, false > { using type = void; };
  60. template< >
  61. struct classify< volatile void*, false, false, false > { using type = void; };
  62. template< >
  63. struct classify< const volatile void*, false, false, false > { using type = void; };
  64. template< typename T, typename U >
  65. struct classify< T U::*, false, false, false > { using type = void; };
  66. } // namespace detail
  67. } // namespace atomics
  68. } // namespace boost
  69. #include <boost/atomic/detail/footer.hpp>
  70. #endif // BOOST_ATOMIC_DETAIL_CLASSIFY_HPP_INCLUDED_