scalar_type.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_TYPE_TRAITS_SCALAR_TYPE_HPP
  11. #define BOOST_COMPUTE_TYPE_TRAITS_SCALAR_TYPE_HPP
  12. #include <boost/preprocessor/cat.hpp>
  13. #include <boost/compute/types/fundamental.hpp>
  14. namespace boost {
  15. namespace compute {
  16. /// Meta-function returning the scalar type for a vector type.
  17. ///
  18. /// For example,
  19. /// \code
  20. /// scalar_type<float4_>::type == float
  21. /// \endcode
  22. template<class Vector>
  23. struct scalar_type
  24. {
  25. /// \internal_
  26. typedef void type;
  27. };
  28. /// \internal_
  29. #define BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTION(scalar) \
  30. template<> \
  31. struct scalar_type<BOOST_PP_CAT(scalar, _)> \
  32. { \
  33. typedef BOOST_PP_CAT(scalar, _) type; \
  34. };
  35. /// \internal_
  36. #define BOOST_COMPUTE_DECLARE_VECTOR_SCALAR_TYPE_FUNCTION(scalar, size) \
  37. template<> \
  38. struct scalar_type<BOOST_PP_CAT(BOOST_PP_CAT(scalar, size), _)> \
  39. { \
  40. typedef BOOST_PP_CAT(scalar, _) type; \
  41. };
  42. /// \internal_
  43. #define BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(scalar) \
  44. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTION(scalar) \
  45. BOOST_COMPUTE_DECLARE_VECTOR_SCALAR_TYPE_FUNCTION(scalar, 2) \
  46. BOOST_COMPUTE_DECLARE_VECTOR_SCALAR_TYPE_FUNCTION(scalar, 4) \
  47. BOOST_COMPUTE_DECLARE_VECTOR_SCALAR_TYPE_FUNCTION(scalar, 8) \
  48. BOOST_COMPUTE_DECLARE_VECTOR_SCALAR_TYPE_FUNCTION(scalar, 16)
  49. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(char)
  50. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(uchar)
  51. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(short)
  52. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(ushort)
  53. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(int)
  54. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(uint)
  55. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(long)
  56. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(ulong)
  57. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(float)
  58. BOOST_COMPUTE_DECLARE_SCALAR_TYPE_FUNCTIONS(double)
  59. } // end compute namespace
  60. } // end boost namespace
  61. #endif // BOOST_COMPUTE_TYPE_TRAITS_SCALAR_TYPE_HPP