]>
Commit | Line | Data |
---|---|---|
b32b8144 | 1 | // Copyright Louis Dionne 2013-2017 |
7c673cae FG |
2 | // Distributed under the Boost Software License, Version 1.0. |
3 | // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
4 | ||
5 | #ifndef BOOST_HANA_TEST_STRUCT_MINIMAL_STRUCT_HPP | |
6 | #define BOOST_HANA_TEST_STRUCT_MINIMAL_STRUCT_HPP | |
7 | ||
8 | #include <boost/hana/at.hpp> | |
9 | #include <boost/hana/fwd/accessors.hpp> | |
10 | #include <boost/hana/pair.hpp> | |
11 | #include <boost/hana/range.hpp> | |
12 | #include <boost/hana/tuple.hpp> | |
13 | #include <boost/hana/unpack.hpp> | |
14 | ||
15 | ||
16 | template <int N> | |
17 | struct minimal_struct_tag; | |
18 | ||
19 | template <typename ...Members> | |
20 | struct minimal_struct_t { | |
21 | boost::hana::tuple<Members...> members; | |
22 | using hana_tag = minimal_struct_tag<sizeof...(Members)>; | |
23 | }; | |
24 | ||
25 | struct obj_t { | |
26 | template <typename ...Members> | |
27 | constexpr minimal_struct_t<Members...> operator()(Members ...members) const { | |
28 | return {{static_cast<Members&&>(members)...}}; | |
29 | } | |
30 | }; | |
31 | constexpr obj_t obj{}; | |
32 | ||
33 | namespace boost { namespace hana { | |
34 | template <int N> | |
35 | struct accessors_impl<minimal_struct_tag<N>> { | |
36 | template <typename K> | |
37 | struct get_member { | |
38 | template <typename Struct> | |
39 | constexpr decltype(auto) operator()(Struct&& s) const { | |
40 | return hana::at_c<K::value>(static_cast<Struct&&>(s).members); | |
41 | } | |
42 | }; | |
43 | ||
44 | static auto apply() { | |
45 | return hana::unpack(hana::range_c<int, 0, N>, [](auto ...k) { | |
46 | return hana::make_tuple( | |
47 | hana::make_pair(k, get_member<decltype(k)>{})... | |
48 | ); | |
49 | }); | |
50 | } | |
51 | }; | |
52 | }} | |
53 | ||
54 | #endif // !BOOST_HANA_TEST_STRUCT_MINIMAL_STRUCT_HPP |