vector_size.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_VECTOR_SIZE_HPP
  11. #define BOOST_COMPUTE_TYPE_TRAITS_VECTOR_SIZE_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 size (number of components) of a vector type
  17. /// \p T. For scalar types this function returns \c 1.
  18. ///
  19. /// For example,
  20. /// \code
  21. /// vector_size<float>::value == 1
  22. /// vector_size<float4_>::value == 4
  23. /// \endcode
  24. template<class T>
  25. struct vector_size
  26. {
  27. /// \internal_
  28. BOOST_STATIC_CONSTANT(size_t, value = 1);
  29. };
  30. /// \internal_
  31. #define BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTION(scalar, size) \
  32. template<> \
  33. struct vector_size<BOOST_PP_CAT(BOOST_PP_CAT(scalar, size), _)> \
  34. { \
  35. BOOST_STATIC_CONSTANT(size_t, value = size); \
  36. };
  37. /// \internal_
  38. #define BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(scalar) \
  39. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTION(scalar, 2) \
  40. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTION(scalar, 4) \
  41. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTION(scalar, 8) \
  42. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTION(scalar, 16)
  43. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(char)
  44. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(uchar)
  45. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(short)
  46. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(ushort)
  47. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(int)
  48. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(uint)
  49. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(long)
  50. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(ulong)
  51. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(float)
  52. BOOST_COMPUTE_DECLARE_VECTOR_SIZE_FUNCTIONS(double)
  53. } // end compute namespace
  54. } // end boost namespace
  55. #endif // BOOST_COMPUTE_TYPE_TRAITS_VECTOR_SIZE_HPP