Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit 9ca1210

Browse files
authored
Make any_system_tag only convertible to other system tags (#1687)
1 parent 64ab693 commit 9ca1210

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

thrust/detail/execution_policy.h

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include <thrust/detail/config.h>
20+
#include <thrust/detail/type_traits.h>
2021

2122
THRUST_NAMESPACE_BEGIN
2223

@@ -66,6 +67,11 @@ const DerivedPolicy &derived_cast(const execution_policy_base<DerivedPolicy> &x)
6667
return static_cast<const DerivedPolicy&>(x);
6768
}
6869

70+
template <class>
71+
struct is_system_tag
72+
: false_type
73+
{};
74+
6975
} // end detail
7076

7177
template<typename DerivedPolicy>

thrust/iterator/detail/any_system_tag.h

+15-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,28 @@
1818

1919
#include <thrust/detail/config.h>
2020
#include <thrust/detail/execution_policy.h>
21+
#include <thrust/detail/type_traits.h>
2122

2223
THRUST_NAMESPACE_BEGIN
2324

2425
struct any_system_tag
2526
: thrust::execution_policy<any_system_tag>
2627
{
27-
// allow any_system_tag to convert to any type at all
28-
// XXX make this safer using enable_if<is_tag<T>> upon c++11
29-
template<typename T> operator T () const {return T();}
28+
// allow any_system_tag to convert to any system tag type
29+
template<typename T,
30+
typename detail::enable_if<detail::is_system_tag<T>::value, int>::type = 0>
31+
operator T () const {return T();}
3032
};
3133

34+
namespace detail {
35+
36+
template <>
37+
struct is_system_tag<any_system_tag>
38+
: true_type
39+
{};
40+
41+
}
42+
43+
3244
THRUST_NAMESPACE_END
3345

thrust/iterator/detail/device_system_tag.h

+9
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ THRUST_NAMESPACE_BEGIN
2727

2828
typedef thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::tag device_system_tag;
2929

30+
namespace detail {
31+
32+
template <>
33+
struct is_system_tag<device_system_tag>
34+
: true_type
35+
{};
36+
37+
}
38+
3039
THRUST_NAMESPACE_END

thrust/iterator/detail/host_system_tag.h

+9
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ THRUST_NAMESPACE_BEGIN
2727

2828
typedef thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::tag host_system_tag;
2929

30+
namespace detail {
31+
32+
template <>
33+
struct is_system_tag<host_system_tag>
34+
: true_type
35+
{};
36+
37+
}
38+
3039
THRUST_NAMESPACE_END

0 commit comments

Comments
 (0)