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.
17 // Portions of this code are derived from
19 // Manjunath Kudlur's Carbon library
23 // Based on Boost.Phoenix v1.2
24 // Copyright (c) 2001-2002 Joel de Guzman
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>
42 template<typename Action, typename Env>
45 typedef typename Action::template result<Env>::type type;
48 template<typename Eval>
52 typedef Eval eval_type;
58 actor(const Eval &base);
61 typename apply_actor<eval_type, thrust::null_type >::type
62 operator()(void) const;
66 typename apply_actor<eval_type, thrust::tuple<T0&> >::type
67 operator()(T0 &_0) const;
69 template<typename T0, typename T1>
71 typename apply_actor<eval_type, thrust::tuple<T0&,T1&> >::type
72 operator()(T0 &_0, T1 &_1) const;
74 template<typename T0, typename T1, typename T2>
76 typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&> >::type
77 operator()(T0 &_0, T1 &_1, T2 &_2) const;
79 template<typename T0, typename T1, typename T2, typename T3>
81 typename apply_actor<eval_type, thrust::tuple<T0&,T1&,T2&,T3&> >::type
82 operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3) const;
84 template<typename T0, typename T1, typename T2, typename T3, typename T4>
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;
89 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
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;
94 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
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;
99 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
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;
104 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
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;
109 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
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;
116 typename assign_result<Eval,T>::type
117 operator=(const T &_1) const;
120 // in general, as_actor should turn things into values
124 typedef value<T> type;
126 static inline __host__ __device__ type convert(const T &x)
132 // specialization for things which are already actors
133 template<typename Eval>
134 struct as_actor<actor<Eval> >
136 typedef actor<Eval> type;
138 static inline __host__ __device__ const type &convert(const actor<Eval> &x)
145 typename as_actor<T>::type
147 make_actor(const T &x)
149 return as_actor<T>::convert(x);
150 } // end make_actor()
154 // provide specializations for result_of for nullary, unary, and binary invocations of actor
155 template<typename Eval>
157 thrust::detail::functional::actor<Eval>()
160 typedef typename thrust::detail::functional::apply_actor<
161 thrust::detail::functional::actor<Eval>,
166 template<typename Eval, typename Arg1>
168 thrust::detail::functional::actor<Eval>(Arg1)
171 typedef typename thrust::detail::functional::apply_actor<
172 thrust::detail::functional::actor<Eval>,
177 template<typename Eval, typename Arg1, typename Arg2>
179 thrust::detail::functional::actor<Eval>(Arg1,Arg2)
182 typedef typename thrust::detail::functional::apply_actor<
183 thrust::detail::functional::actor<Eval>,
184 thrust::tuple<Arg1,Arg2>
191 #include <thrust/detail/functional/actor.inl>