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>
34 enum class ExtraArgsInsertPolicy
37 * Extra arguments will be add at the end of the argument list
38 * passed to operation call.
43 * Extra arguments will be add at the begining of the argument list
44 * passed to operation call.
49 template<ExtraArgsInsertPolicy>
50 struct _ApplyDispatchByPolicy;
52 template<typename Result = void,
53 ExtraArgsInsertPolicy insertPolicy = ExtraArgsInsertPolicy::Append,
57 Result Apply(Operation op,
58 const std::tuple<ArgsT ...>& t,
61 return _ApplyDispatchByPolicy<insertPolicy>::
62 template Apply<Result>(op, t, std::forward<ArgsE>(extra) ...);
65 template<size_t N, size_t M>
68 template<typename Result,
73 static Result Apply(Operation op,
74 const std::tuple<ArgsT1 ...>& t1,
75 const std::tuple<ArgsT2 ...>& t2,
78 return _ApplyTuple<N - 1, M>::
79 template Apply<Result>(op,
83 std::forward<Args>(args) ...);
88 struct _ApplyTuple<0, M>
90 template<typename Result,
95 static Result Apply(Operation op,
96 const std::tuple<ArgsT1 ...>& t1,
97 const std::tuple<ArgsT2 ...>& t2,
100 return _ApplyTuple<0, M - 1>::
101 template Apply<Result>(op,
105 std::forward<Args>(args) ...);
110 struct _ApplyTuple<0, 0>
112 template<typename Result,
117 static Result Apply(Operation op,
118 const std::tuple<ArgsT1 ...>&,
119 const std::tuple<ArgsT2 ...>&,
122 return op(std::forward<Args>(args) ...);
129 template<typename Result,
133 static Result Apply(Operation op,
134 const std::tuple<ArgsT ...>& t,
137 return _ApplyArgs<N - 1>::
138 template Apply<Result>(op,
141 std::forward<Args>(args) ...);
148 template<typename Result,
152 static Result Apply(Operation op,
153 const std::tuple<ArgsT ...>&,
156 return op(std::forward<Args>(args) ...);
161 struct _ApplyDispatchByPolicy<ExtraArgsInsertPolicy::Append>
163 template<typename Result,
167 static Result Apply(Operation op,
168 const std::tuple<ArgsT ...>& t,
171 return _ApplyArgs<sizeof ... (ArgsT)>::
172 template Apply<Result>(op,
174 std::forward<ArgsE>(extra) ...);
179 struct _ApplyDispatchByPolicy<ExtraArgsInsertPolicy::Prepend>
181 template<typename Result,
185 static Result Apply(Operation op,
186 const std::tuple<ArgsT ...>& t,
189 return _ApplyTuple<sizeof ... (ArgsT), sizeof ... (ArgsE)>::
190 template Apply<Result>(op,
192 std::make_tuple(std::forward<ArgsE>(extra) ...));
197 #endif // __GXX_EXPERIMENTAL_CXX0X__
199 #endif // DPL_APPLY_H_