1 /* 2 * Copyright 2008-2013 NVIDIA Corporation 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 #pragma once 18 19 #include <thrust/detail/config.h> 20 21 namespace thrust 22 { 23 namespace detail 24 { 25 26 struct execution_policy_marker {}; 27 28 // execution_policy_base serves as a guard against 29 // inifinite recursion in thrust entry points: 30 // 31 // template<typename DerivedPolicy> 32 // void foo(const thrust::detail::execution_policy_base<DerivedPolicy> &s) 33 // { 34 // using thrust::system::detail::generic::foo; 35 // 36 // foo(thrust::detail::derived_cast(thrust::detail::strip_const(s)); 37 // } 38 // 39 // foo is not recursive when 40 // 1. DerivedPolicy is derived from thrust::execution_policy below 41 // 2. generic::foo takes thrust::execution_policy as a parameter 42 template<typename DerivedPolicy> 43 struct execution_policy_base : execution_policy_marker {}; 44 45 46 template<typename DerivedPolicy> 47 THRUST_CONSTEXPR __host__ __device__ strip_const(const execution_policy_base<DerivedPolicy> & x)48execution_policy_base<DerivedPolicy> &strip_const(const execution_policy_base<DerivedPolicy> &x) 49 { 50 return const_cast<execution_policy_base<DerivedPolicy>&>(x); 51 } 52 53 54 template<typename DerivedPolicy> 55 THRUST_CONSTEXPR __host__ __device__ derived_cast(execution_policy_base<DerivedPolicy> & x)56DerivedPolicy &derived_cast(execution_policy_base<DerivedPolicy> &x) 57 { 58 return static_cast<DerivedPolicy&>(x); 59 } 60 61 62 template<typename DerivedPolicy> 63 THRUST_CONSTEXPR __host__ __device__ derived_cast(const execution_policy_base<DerivedPolicy> & x)64const DerivedPolicy &derived_cast(const execution_policy_base<DerivedPolicy> &x) 65 { 66 return static_cast<const DerivedPolicy&>(x); 67 } 68 69 } // end detail 70 71 template<typename DerivedPolicy> 72 struct execution_policy 73 : thrust::detail::execution_policy_base<DerivedPolicy> 74 {}; 75 76 } // end thrust 77 78