Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
visit-fields.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Jan Olszak (j.olszak@samsung.com)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 
26 #ifndef CARGO_VISIT_FIELDS_HPP
27 #define CARGO_VISIT_FIELDS_HPP
28 
29 #include <string>
30 #include <tuple>
31 
32 namespace {
33 
34 template<int I, class T, class F, typename ... A>
35 struct visitImpl
36 {
37  static void visit(T& t, F f, A&& ... args)
38  {
39  visitImpl<I - 1, T, F, A...>::visit(t, f, std::forward<A>(args)...);
40  f->visit(args..., std::get<I>(t));
41  }
42 };
43 
44 template<class T, class F, typename ... A>
45 struct visitImpl<0, T, F, A...>
46 {
47  static void visit(T& t, F f, A&& ... args)
48  {
49  f->visit(args..., std::get<0>(t));
50  }
51 };
52 
53 } // namespace
54 
55 namespace cargo {
56 
57 template<class T, class F, typename ... A>
58 void visitFields(T& t, F f, A ... args)
59 {
60  visitImpl<std::tuple_size<T>::value - 1, T, F, A...>::visit(t, f, std::forward<A>(args)...);
61 }
62 
63 } // namespace cargo
64 
65 #endif // CARGO_VISIT_FIELDS_HPP
void visitFields(T &t, F f, A...args)
Definition: visit-fields.hpp:58