66#include < sycl/detail/core.hpp>
77using namespace sycl ;
88
9- template <typename T> T op (T x) { return x + 1 ; }
9+ template <typename T> struct Increment {
10+ T operator ()(T x) const { return x + 1 ; }
11+ };
1012
11- template <typename T> int test (queue &q) {
13+ template <typename T> struct IntCastThenIncrement {
14+ int operator ()(T x) const { return static_cast <int >(x) + 1 ; }
15+ };
16+
17+ template <typename Op> int test (queue &q) {
1218 double res[] = {1 .};
1319 {
1420 buffer<double , 1 > buf (res, 1 );
1521 q.submit ([&](handler &cgh) {
1622 accessor acc (buf, cgh);
17- cgh.single_task ([=] { acc[0 ] = op<T> (acc[0 ]); });
23+ cgh.single_task ([=] { acc[0 ] = Op () (acc[0 ]); });
1824 }).wait ();
1925 }
2026 double ref = 1 .;
21- ref = op<T> (ref);
27+ ref = Op () (ref);
2228 if (res[0 ] != ref) {
23- std::cout << typeid (T ).name () << " fail: got " << res[0 ] << " , expected "
29+ std::cout << typeid (Op ).name () << " fail: got " << res[0 ] << " , expected "
2430 << ref << " \n " ;
2531 return 1 ;
2632 }
@@ -31,13 +37,16 @@ int main() {
3137 int nfail = 0 ;
3238 queue q;
3339
34- nfail += test<int >(q);
35- nfail += test<long >(q);
36- nfail += test<float >(q);
40+ nfail += test<Increment<int >>(q);
41+ nfail += test<Increment<long >>(q);
42+ nfail += test<Increment<float >>(q);
43+
3744 if (q.get_device ().has (aspect::fp64))
38- nfail += test<double >(q);
45+ nfail += test<Increment<double >>(q);
46+
47+ nfail += test<IntCastThenIncrement<double >>(q);
3948
4049 if (nfail == 0 )
4150 std::cout << " success\n " ;
4251 return nfail;
43- }
52+ }
0 commit comments