OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / detail / functional / actor.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 // Portions of this code are derived from
18 //
19 // Manjunath Kudlur's Carbon library
20 //
21 // and
22 //
23 // Based on Boost.Phoenix v1.2
24 // Copyright (c) 2001-2002 Joel de Guzman
25
26 #pragma once
27
28 #include <thrust/detail/config.h>
29 #include <thrust/tuple.h>
30 #include <thrust/detail/functional/value.h>
31 #include <thrust/detail/functional/composite.h>
32 #include <thrust/detail/functional/operators/assignment_operator.h>
33 #include <thrust/detail/type_traits/result_of.h>
34
35 namespace thrust
36 {
37 namespace detail
38 {
39 namespace functional
40 {
41
42 template<typename Action, typename Env>
43   struct apply_actor
44 {
45   typedef typename Action::template result<Env>::type type;
46 };
47
48 template<typename Eval>
49   struct actor
50     : Eval
51 {
52   typedef Eval eval_type;
53
54   __host__ __device__
55   actor(void);
56
57   __host__ __device__
58   actor(const Eval &base);
59
60   __host__ __device__
61   typename apply_actor<eval_type, thrust::null_type >::type
62   operator()(void) const;
63
64   template<typename T0>
65   __host__ __device__
66   typename apply_actor<eval_type, thrust::tuple<T0&> >::type
67   operator()(T0 &_0) const;
68
69   template<typename T0, typename T1>
70   __host__ __device__
71   typename apply_actor<eval_type, thrust::tuple<T0&,T1&> >::type
72   operator()(T0 &_0, T1 &_1) const;
73
74   template<typename T0, typename T1, typename T2>
75   __host__ __device__
76   typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&> >::type
77   operator()(T0 &_0, T1 &_1, T2 &_2) const;
78
79   template<typename T0, typename T1, typename T2, typename T3>
80   __host__ __device__
81   typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&,T3&> >::type
82   operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3) const;
83
84   template<typename T0, typename T1, typename T2, typename T3, typename T4>
85   __host__ __device__
86   typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&,T3&,T4&> >::type
87   operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4) const;
88
89   template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
90   __host__ __device__
91   typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&> >::type
92   operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5) const;
93
94   template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
95   __host__ __device__
96   typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&> >::type
97   operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6) const;
98
99   template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
100   __host__ __device__
101   typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&,T7&> >::type
102   operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7) const;
103
104   template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
105   __host__ __device__
106   typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&,T7&,T8&> >::type
107   operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7, T8 &_8) const;
108
109   template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
110   __host__ __device__
111   typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&,T7&,T8&,T9&> >::type
112   operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7, T8 &_8, T9 &_9) const;
113
114   template<typename T>
115   __host__ __device__
116   typename assign_result<Eval,T>::type
117   operator=(const T &_1) const;
118 }; // end actor
119
120 // in general, as_actor should turn things into values
121 template<typename T>
122   struct as_actor
123 {
124   typedef value<T> type;
125
126   static inline __host__ __device__ type convert(const T &x)
127   {
128     return val(x);
129   } // end convert()
130 }; // end as_actor
131
132 // specialization for things which are already actors
133 template<typename Eval>
134   struct as_actor<actor<Eval> >
135 {
136   typedef actor<Eval> type;
137
138   static inline __host__ __device__ const type &convert(const actor<Eval> &x)
139   {
140     return x;
141   } // end convert()
142 }; // end as_actor
143
144 template<typename T>
145   typename as_actor<T>::type
146   __host__ __device__
147     make_actor(const T &x)
148 {
149   return as_actor<T>::convert(x);
150 } // end make_actor()
151
152 } // end functional
153
154 // provide specializations for result_of for nullary, unary, and binary invocations of actor
155 template<typename Eval>
156   struct result_of<
157     thrust::detail::functional::actor<Eval>()
158   >
159 {
160   typedef typename thrust::detail::functional::apply_actor<
161     thrust::detail::functional::actor<Eval>,
162     thrust::null_type
163   >::type type;
164 }; // end result_of
165
166 template<typename Eval, typename Arg1>
167   struct result_of<
168     thrust::detail::functional::actor<Eval>(Arg1)
169   >
170 {
171   typedef typename thrust::detail::functional::apply_actor<
172     thrust::detail::functional::actor<Eval>,
173     thrust::tuple<Arg1>
174   >::type type;
175 }; // end result_of
176
177 template<typename Eval, typename Arg1, typename Arg2>
178   struct result_of<
179     thrust::detail::functional::actor<Eval>(Arg1,Arg2)
180   >
181 {
182   typedef typename thrust::detail::functional::apply_actor<
183     thrust::detail::functional::actor<Eval>,
184     thrust::tuple<Arg1,Arg2>
185   >::type type;
186 }; // end result_of
187
188 } // end detail
189 } // end thrust
190
191 #include <thrust/detail/functional/actor.inl>
192