OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / detail / execution_policy.h
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
27 // execution_policy_base serves as a guard against
28 // inifinite recursion in thrust entry points:
29 //
30 // template<typename DerivedPolicy>
31 // void foo(const thrust::detail::execution_policy_base<DerivedPolicy> &s)
32 // {
33 //   using thrust::system::detail::generic::foo;
34 //
35 //   foo(thrust::detail::derived_cast(thrust::detail::strip_const(s));
36 // }
37 //
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 {};
42
43
44 template<typename DerivedPolicy>
45 __host__ __device__
46 inline execution_policy_base<DerivedPolicy> &strip_const(const execution_policy_base<DerivedPolicy> &x)
47 {
48   return const_cast<execution_policy_base<DerivedPolicy>&>(x);
49 }
50
51
52 template<typename DerivedPolicy>
53 __host__ __device__
54 inline DerivedPolicy &derived_cast(execution_policy_base<DerivedPolicy> &x)
55 {
56   return static_cast<DerivedPolicy&>(x);
57 }
58
59
60 template<typename DerivedPolicy>
61 __host__ __device__
62 inline const DerivedPolicy &derived_cast(const execution_policy_base<DerivedPolicy> &x)
63 {
64   return static_cast<const DerivedPolicy&>(x);
65 }
66
67
68 } // end detail
69
70
71 template<typename DerivedPolicy>
72   struct execution_policy
73     : thrust::detail::execution_policy_base<DerivedPolicy>
74 {};
75
76
77 } // end thrust
78