Skip to content

Commit bc75c55

Browse files
authored
Merge pull request #737 from ddemidov/osx-size_t
size_t and ptrdiff_t need special treatment on OSX
2 parents 0c2f749 + c9522ad commit bc75c55

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

include/boost/compute/types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
#include <boost/compute/types/pair.hpp>
2121
#include <boost/compute/types/struct.hpp>
2222
#include <boost/compute/types/tuple.hpp>
23+
#include <boost/compute/types/size_t.hpp>
2324

2425
#endif // BOOST_COMPUTE_TYPES_HPP
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//---------------------------------------------------------------------------//
2+
// Copyright (c) 2017 Denis Demidov <[email protected]>
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+
11+
// size_t and ptrdiff_t need special treatment on OSX since those are not
12+
// typedefs for ulong and long here:
13+
#if defined(__APPLE__) && !defined(BOOST_COMPUTE_TYPES_SIZE_T_HPP)
14+
#define BOOST_COMPUTE_TYPES_SIZE_T_HPP
15+
16+
#include <sstream>
17+
18+
#include <boost/mpl/if.hpp>
19+
20+
#include <boost/compute/type_traits/is_fundamental.hpp>
21+
#include <boost/compute/type_traits/type_name.hpp>
22+
#include <boost/compute/detail/meta_kernel.hpp>
23+
24+
namespace boost {
25+
namespace compute {
26+
27+
template <> struct is_fundamental<size_t> : boost::true_type {};
28+
template <> struct is_fundamental<ptrdiff_t> : boost::true_type {};
29+
30+
namespace detail {
31+
32+
template <> struct type_name_trait<size_t>
33+
: type_name_trait<
34+
boost::mpl::if_c<sizeof(size_t) == sizeof(cl_uint), cl_uint, cl_ulong>::type
35+
>
36+
{};
37+
38+
template <> struct type_name_trait<ptrdiff_t>
39+
: type_name_trait<
40+
boost::mpl::if_c<sizeof(ptrdiff_t) == sizeof(cl_int), cl_int, cl_long>::type
41+
>
42+
{};
43+
44+
inline meta_kernel& operator<<(meta_kernel &k, size_t v) {
45+
std::ostringstream s;
46+
s << v;
47+
return k << s.str();
48+
}
49+
50+
inline meta_kernel& operator<<(meta_kernel &k, ptrdiff_t v) {
51+
std::ostringstream s;
52+
s << v;
53+
return k << s.str();
54+
}
55+
56+
} // end detail namespace
57+
} // end compute namespace
58+
} // end boost namespace
59+
60+
#endif

0 commit comments

Comments
 (0)