size_t.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2017 Denis Demidov <dennis.demidov@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. // size_t and ptrdiff_t need special treatment on OSX since those are not
  11. // typedefs for ulong and long here:
  12. #if defined(__APPLE__) && !defined(BOOST_COMPUTE_TYPES_SIZE_T_HPP)
  13. #define BOOST_COMPUTE_TYPES_SIZE_T_HPP
  14. #include <sstream>
  15. #include <boost/mpl/if.hpp>
  16. #include <boost/compute/type_traits/is_fundamental.hpp>
  17. #include <boost/compute/type_traits/type_name.hpp>
  18. #include <boost/compute/detail/meta_kernel.hpp>
  19. namespace boost {
  20. namespace compute {
  21. template <> struct is_fundamental<size_t> : boost::true_type {};
  22. template <> struct is_fundamental<ptrdiff_t> : boost::true_type {};
  23. namespace detail {
  24. template <> struct type_name_trait<size_t>
  25. : type_name_trait<
  26. boost::mpl::if_c<sizeof(size_t) == sizeof(cl_uint), cl_uint, cl_ulong>::type
  27. >
  28. {};
  29. template <> struct type_name_trait<ptrdiff_t>
  30. : type_name_trait<
  31. boost::mpl::if_c<sizeof(ptrdiff_t) == sizeof(cl_int), cl_int, cl_long>::type
  32. >
  33. {};
  34. inline meta_kernel& operator<<(meta_kernel &k, size_t v) {
  35. std::ostringstream s;
  36. s << v;
  37. return k << s.str();
  38. }
  39. inline meta_kernel& operator<<(meta_kernel &k, ptrdiff_t v) {
  40. std::ostringstream s;
  41. s << v;
  42. return k << s.str();
  43. }
  44. } // end detail namespace
  45. } // end compute namespace
  46. } // end boost namespace
  47. #endif