2 * Copyright 2008-2013 NVIDIA Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <thrust/detail/config.h>
27 // execution_policy_base serves as a guard against
28 // inifinite recursion in thrust entry points:
30 // template<typename DerivedPolicy>
31 // void foo(const thrust::detail::execution_policy_base<DerivedPolicy> &s)
33 // using thrust::system::detail::generic::foo;
35 // foo(thrust::detail::derived_cast(thrust::detail::strip_const(s));
38 // foo is not recursive when
39 // 1. DerivedPolicy is derived from thrust::execution_policy below
40 // 2. generic::foo takes thrust::execution_policy as a parameter
41 template<typename DerivedPolicy> struct execution_policy_base {};
44 template<typename DerivedPolicy>
46 inline execution_policy_base<DerivedPolicy> &strip_const(const execution_policy_base<DerivedPolicy> &x)
48 return const_cast<execution_policy_base<DerivedPolicy>&>(x);
52 template<typename DerivedPolicy>
54 inline DerivedPolicy &derived_cast(execution_policy_base<DerivedPolicy> &x)
56 return static_cast<DerivedPolicy&>(x);
60 template<typename DerivedPolicy>
62 inline const DerivedPolicy &derived_cast(const execution_policy_base<DerivedPolicy> &x)
64 return static_cast<const DerivedPolicy&>(x);
71 template<typename DerivedPolicy>
72 struct execution_policy
73 : thrust::detail::execution_policy_base<DerivedPolicy>