]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <%# |
2 | This is an ERB [1] template file used to generate the | |
3 | <boost/hana/detail/struct_macros.hpp> header. The maximum | |
4 | number of members that can be handled by the macros can | |
5 | be controlled with the 'MAX_NUMBER_OF_MEMBERS' variable, | |
6 | which can be set when calling ERB to generate the header: | |
7 | ||
8 | export MAX_NUMBER_OF_MEMBERS=55; erb struct_macros.erb.hpp | |
9 | ||
10 | 'MAX_NUMBER_OF_MEMBERS' must be <= 62, otherwise an error is triggered. | |
11 | In case 'MAX_NUMBER_OF_MEMBERS' is not specified, it defaults to 40. | |
12 | ||
13 | [1]: http://en.wikipedia.org/wiki/ERuby | |
14 | %> | |
15 | ||
16 | <% | |
17 | MAX_NUMBER_OF_MEMBERS = (ENV["MAX_NUMBER_OF_MEMBERS"] || 40).to_i | |
18 | raise "MAX_NUMBER_OF_MEMBERS must be <= 62" if MAX_NUMBER_OF_MEMBERS > 62 | |
19 | %> | |
20 | ||
21 | /*! | |
22 | @file | |
23 | Defines the `BOOST_HANA_DEFINE_STRUCT`, `BOOST_HANA_ADAPT_STRUCT`, and | |
24 | `BOOST_HANA_ADAPT_ADT` macros. | |
25 | ||
26 | @copyright Louis Dionne 2013-2016 | |
27 | Distributed under the Boost Software License, Version 1.0. | |
28 | (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
29 | */ | |
30 | ||
31 | ////////////////////////////////////////////////////////////////////////////// | |
32 | // THIS FILE IS GENERATED FROM THE <boost/hana/detail/struct_macros.erb.hpp> | |
33 | // ERB TEMPLATE. DO NOT EDIT THIS FILE DIRECTLY. | |
34 | // | |
35 | // THE ERB TEMPLATE CONTAINS INFORMATION ABOUT HOW TO REGENERATE THIS FILE. | |
36 | ////////////////////////////////////////////////////////////////////////////// | |
37 | ||
38 | #ifndef BOOST_HANA_DETAIL_STRUCT_MACROS_HPP | |
39 | #define BOOST_HANA_DETAIL_STRUCT_MACROS_HPP | |
40 | ||
41 | #include <boost/hana/config.hpp> | |
42 | #include <boost/hana/detail/preprocessor.hpp> | |
43 | #include <boost/hana/pair.hpp> | |
44 | #include <boost/hana/string.hpp> | |
45 | #include <boost/hana/tuple.hpp> | |
46 | ||
47 | #include <cstddef> | |
48 | #include <utility> | |
49 | ||
50 | ||
51 | BOOST_HANA_NAMESPACE_BEGIN namespace struct_detail { | |
52 | template <typename Memptr, Memptr ptr> | |
53 | struct member_ptr { | |
54 | template <typename T> | |
55 | constexpr decltype(auto) operator()(T&& t) const | |
56 | { return static_cast<T&&>(t).*ptr; } | |
57 | }; | |
58 | ||
59 | constexpr std::size_t strlen(char const* s) { | |
60 | std::size_t n = 0; | |
61 | while (*s++ != '\0') | |
62 | ++n; | |
63 | return n; | |
64 | } | |
65 | ||
66 | template <std::size_t n, typename Names, std::size_t ...i> | |
67 | constexpr auto prepare_member_name_impl(std::index_sequence<i...>) { | |
68 | return hana::string_c<hana::at_c<n>(Names::get())[i]...>; | |
69 | } | |
70 | ||
71 | template <std::size_t n, typename Names> | |
72 | constexpr auto prepare_member_name() { | |
73 | constexpr std::size_t len = strlen(hana::at_c<n>(Names::get())); | |
74 | return prepare_member_name_impl<n, Names>(std::make_index_sequence<len>{}); | |
75 | } | |
76 | } BOOST_HANA_NAMESPACE_END | |
77 | ||
78 | ////////////////////////////////////////////////////////////////////////////// | |
79 | // BOOST_HANA_ADAPT_STRUCT | |
80 | ////////////////////////////////////////////////////////////////////////////// | |
81 | template <typename ...> | |
82 | struct BOOST_HANA_ADAPT_STRUCT_must_be_called_in_the_global_namespace; | |
83 | ||
84 | #define BOOST_HANA_ADAPT_STRUCT(...) \ | |
85 | template <> \ | |
86 | struct BOOST_HANA_ADAPT_STRUCT_must_be_called_in_the_global_namespace<>; \ | |
87 | BOOST_HANA_ADAPT_STRUCT_IMPL(BOOST_HANA_PP_NARG(__VA_ARGS__), __VA_ARGS__)\ | |
88 | static_assert(true, "force the usage of a trailing semicolon") \ | |
89 | /**/ | |
90 | ||
91 | #define BOOST_HANA_ADAPT_STRUCT_IMPL(N, ...) \ | |
92 | BOOST_HANA_PP_CONCAT(BOOST_HANA_ADAPT_STRUCT_IMPL_, N)(__VA_ARGS__) | |
93 | ||
94 | <% (0..MAX_NUMBER_OF_MEMBERS).each do |n| %> | |
95 | #define BOOST_HANA_ADAPT_STRUCT_IMPL_<%= n+1 %>(TYPE <%= (1..n).map { |i| ", m#{i}" }.join %>) \ | |
96 | namespace boost { namespace hana { \ | |
97 | template <> \ | |
98 | struct accessors_impl<TYPE> { \ | |
99 | static constexpr auto apply() { \ | |
100 | struct member_names { \ | |
101 | static constexpr auto get() { \ | |
102 | return ::boost::hana::make_tuple( \ | |
103 | <%= (1..n).map { |i| "BOOST_HANA_PP_STRINGIZE(m#{i})" }.join(', ') %> \ | |
104 | ); \ | |
105 | } \ | |
106 | }; \ | |
107 | return ::boost::hana::make_tuple( \ | |
108 | <%= (1..n).map { |i| "::boost::hana::make_pair(::boost::hana::struct_detail::prepare_member_name<#{i-1}, member_names>(), ::boost::hana::struct_detail::member_ptr<decltype(&TYPE::m#{i}), &TYPE::m#{i}>{})" }.join(', ') %>\ | |
109 | ); \ | |
110 | } \ | |
111 | }; \ | |
112 | }} \ | |
113 | /**/ | |
114 | <% end %> | |
115 | ||
116 | ////////////////////////////////////////////////////////////////////////////// | |
117 | // BOOST_HANA_ADAPT_ADT | |
118 | ////////////////////////////////////////////////////////////////////////////// | |
119 | template <typename ...> | |
120 | struct BOOST_HANA_ADAPT_ADT_must_be_called_in_the_global_namespace; | |
121 | ||
122 | #define BOOST_HANA_ADAPT_ADT(...) \ | |
123 | template <> \ | |
124 | struct BOOST_HANA_ADAPT_ADT_must_be_called_in_the_global_namespace<>; \ | |
125 | BOOST_HANA_ADAPT_ADT_IMPL(BOOST_HANA_PP_NARG(__VA_ARGS__), __VA_ARGS__) \ | |
126 | static_assert(true, "force the usage of a trailing semicolon") \ | |
127 | /**/ | |
128 | ||
129 | #define BOOST_HANA_ADAPT_ADT_IMPL(N, ...) \ | |
130 | BOOST_HANA_PP_CONCAT(BOOST_HANA_ADAPT_ADT_IMPL_, N)(__VA_ARGS__) | |
131 | ||
132 | <% (0..MAX_NUMBER_OF_MEMBERS).each do |n| %> | |
133 | #define BOOST_HANA_ADAPT_ADT_IMPL_<%= n+1 %>(TYPE <%= (1..n).map { |i| ", m#{i}" }.join %>) \ | |
134 | namespace boost { namespace hana { \ | |
135 | template <> \ | |
136 | struct accessors_impl<TYPE> { \ | |
137 | template <typename ...> \ | |
138 | static constexpr auto apply() { \ | |
139 | struct member_names { \ | |
140 | static constexpr auto get() { \ | |
141 | return ::boost::hana::make_tuple( \ | |
142 | <%= (1..n).map { |i| "BOOST_HANA_PP_STRINGIZE(BOOST_HANA_PP_FRONT m#{i})" }.join(', ') %>\ | |
143 | ); \ | |
144 | } \ | |
145 | }; \ | |
146 | return ::boost::hana::make_tuple( \ | |
147 | <%= (1..n).map { |i| "::boost::hana::make_pair(::boost::hana::struct_detail::prepare_member_name<#{i-1}, member_names>(), BOOST_HANA_PP_DROP_FRONT m#{i})" }.join(', ') %>\ | |
148 | ); \ | |
149 | } \ | |
150 | }; \ | |
151 | }} \ | |
152 | /**/ | |
153 | <% end %> | |
154 | ||
155 | ////////////////////////////////////////////////////////////////////////////// | |
156 | // BOOST_HANA_DEFINE_STRUCT | |
157 | ////////////////////////////////////////////////////////////////////////////// | |
158 | #define BOOST_HANA_DEFINE_STRUCT(...) \ | |
159 | BOOST_HANA_DEFINE_STRUCT_IMPL(BOOST_HANA_PP_NARG(__VA_ARGS__), __VA_ARGS__) | |
160 | ||
161 | #define BOOST_HANA_DEFINE_STRUCT_IMPL(N, ...) \ | |
162 | BOOST_HANA_PP_CONCAT(BOOST_HANA_DEFINE_STRUCT_IMPL_, N)(__VA_ARGS__) | |
163 | ||
164 | <% (0..MAX_NUMBER_OF_MEMBERS).each do |n| %> | |
165 | #define BOOST_HANA_DEFINE_STRUCT_IMPL_<%= n+1 %>(TYPE <%= (1..n).map { |i| ", m#{i}" }.join %>) \ | |
166 | <%= (1..n).map { |i| "BOOST_HANA_PP_DROP_BACK m#{i} BOOST_HANA_PP_BACK m#{i};" }.join(' ') %> \ | |
167 | \ | |
168 | struct hana_accessors_impl { \ | |
169 | static constexpr auto apply() { \ | |
170 | struct member_names { \ | |
171 | static constexpr auto get() { \ | |
172 | return ::boost::hana::make_tuple( \ | |
173 | <%= (1..n).map { |i| "BOOST_HANA_PP_STRINGIZE(BOOST_HANA_PP_BACK m#{i})" }.join(', ') %>\ | |
174 | ); \ | |
175 | } \ | |
176 | }; \ | |
177 | return ::boost::hana::make_tuple( \ | |
178 | <%= (1..n).map { |i| "::boost::hana::make_pair(::boost::hana::struct_detail::prepare_member_name<#{i-1}, member_names>(), ::boost::hana::struct_detail::member_ptr<decltype(&TYPE::BOOST_HANA_PP_BACK m#{i}), &TYPE::BOOST_HANA_PP_BACK m#{i}>{})" }.join(', ') %>\ | |
179 | ); \ | |
180 | } \ | |
181 | } \ | |
182 | /**/ | |
183 | <% end %> | |
184 | ||
185 | #endif // !BOOST_HANA_DETAIL_STRUCT_MACROS_HPP |