Bond
 
Loading...
Searching...
No Matches
tuple_fields.h
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4#pragma once
5
6#include <bond/core/config.h>
7
8namespace bond
9{
10namespace detail
11{
12
13template <typename Tuple, uint16_t Id, typename T>
14struct tuple_field
15{
16 typedef Tuple struct_type;
17 typedef typename std::remove_reference<T>::type value_type;
18 typedef typename remove_maybe<value_type>::type field_type;
19 typedef reflection::optional_field_modifier field_modifier;
20
21 static const Metadata metadata;
22 BOND_STATIC_CONSTEXPR uint16_t id = Id;
23
24 static BOND_CONSTEXPR const value_type& GetVariable(const struct_type& obj)
25 {
26 return std::get<id>(obj);
27 }
28
29 static BOND_CONSTEXPR value_type& GetVariable(struct_type& obj)
30 {
31 return std::get<id>(obj);
32 }
33
34 static Metadata GetMetadata()
35 {
36 Metadata m;
37 m.name = "item" + std::to_string(id);
38 return m;
39 }
40};
41
42using ignore_t = decltype(std::ignore);
43
44template <typename Tuple, uint16_t t_id, typename T>
45const Metadata tuple_field<Tuple, t_id, T>::metadata
46 = tuple_field<Tuple, t_id, T>::GetMetadata();
47
48
49template <typename Tuple, uint16_t id, typename ...Rest> struct
50tuple_fields;
51
52template <typename Tuple, uint16_t id, typename T, typename ...Rest> struct
53tuple_fields<Tuple, id, T, Rest...>
54{
55 typedef typename boost::mpl::push_front<
56 typename tuple_fields<Tuple, id + 1, Rest...>::type,
57 tuple_field<Tuple, id, T>
58 >::type type;
59};
60
61template <typename Tuple, uint16_t id, typename ...Rest> struct
62tuple_fields<Tuple, id, const ignore_t&, Rest...>
63 : tuple_fields<Tuple, id + 1, Rest...>
64{};
65
66template <typename Tuple, uint16_t id> struct
67tuple_fields<Tuple, id>
68{
69 typedef typename boost::mpl::list<>::type type;
70};
71
72
73template <typename ...T> struct
74param_list;
75
76template <typename T, typename ...Rest> struct
77param_list<T, Rest...>
78{
79 typedef typename boost::mpl::push_front<
80 typename param_list<Rest...>::type,
81 typename std::add_pointer<T>::type
82 >::type type;
83};
84
85template <typename ...Rest> struct
86param_list<const ignore_t&, Rest...>
87 : param_list<Rest...>
88{};
89
90template <> struct
91param_list<>
92{
93 typedef boost::mpl::list<> type;
94};
95
96} // namespace detail
97
98} // namespace bond
namespace bond
Definition: apply.h:17