2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20 * @brief Implementation file for Apply functionality.
25 #ifndef __GXX_EXPERIMENTAL_CXX0X__ // C++11 compatibility check
26 # include <bits/c++0x_warning.h>
33 enum class ExtraArgsInsertPolicy
36 * Extra arguments will be add at the end of the argument list
37 * passed to operation call.
42 * Extra arguments will be add at the begining of the argument list
43 * passed to operation call.
48 template<ExtraArgsInsertPolicy>
49 struct _ApplyDispatchByPolicy;
51 template<typename Result = void,
52 ExtraArgsInsertPolicy insertPolicy = ExtraArgsInsertPolicy::Append,
56 Result Apply(Operation op,
57 const std::tuple<ArgsT ...>& t,
60 return _ApplyDispatchByPolicy<insertPolicy>::
61 template Apply<Result>(op, t, std::forward<ArgsE>(extra) ...);
64 template<size_t N, size_t M>
67 template<typename Result,
72 static Result Apply(Operation op,
73 const std::tuple<ArgsT1 ...>& t1,
74 const std::tuple<ArgsT2 ...>& t2,
77 return _ApplyTuple<N - 1, M>::
78 template Apply<Result>(op,
82 std::forward<Args>(args) ...);
87 struct _ApplyTuple<0, M>
89 template<typename Result,
94 static Result Apply(Operation op,
95 const std::tuple<ArgsT1 ...>& t1,
96 const std::tuple<ArgsT2 ...>& t2,
99 return _ApplyTuple<0, M - 1>::
100 template Apply<Result>(op,
104 std::forward<Args>(args) ...);
109 struct _ApplyTuple<0, 0>
111 template<typename Result,
116 static Result Apply(Operation op,
117 const std::tuple<ArgsT1 ...>&,
118 const std::tuple<ArgsT2 ...>&,
121 return op(std::forward<Args>(args) ...);
128 template<typename Result,
132 static Result Apply(Operation op,
133 const std::tuple<ArgsT ...>& t,
136 return _ApplyArgs<N - 1>::
137 template Apply<Result>(op,
140 std::forward<Args>(args) ...);
147 template<typename Result,
151 static Result Apply(Operation op,
152 const std::tuple<ArgsT ...>&,
155 return op(std::forward<Args>(args) ...);
160 struct _ApplyDispatchByPolicy<ExtraArgsInsertPolicy::Append>
162 template<typename Result,
166 static Result Apply(Operation op,
167 const std::tuple<ArgsT ...>& t,
170 return _ApplyArgs<sizeof ... (ArgsT)>::
171 template Apply<Result>(op,
173 std::forward<ArgsE>(extra) ...);
178 struct _ApplyDispatchByPolicy<ExtraArgsInsertPolicy::Prepend>
180 template<typename Result,
184 static Result Apply(Operation op,
185 const std::tuple<ArgsT ...>& t,
188 return _ApplyTuple<sizeof ... (ArgsT), sizeof ... (ArgsE)>::
189 template Apply<Result>(op,
191 std::make_tuple(std::forward<ArgsE>(
197 #endif // __GXX_EXPERIMENTAL_CXX0X__
199 #endif // DPL_APPLY_H_