]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::members`. | |
4 | ||
5 | @copyright Louis Dionne 2013-2016 | |
6 | Distributed under the Boost Software License, Version 1.0. | |
7 | (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_MEMBERS_HPP | |
11 | #define BOOST_HANA_MEMBERS_HPP | |
12 | ||
13 | #include <boost/hana/fwd/members.hpp> | |
14 | ||
15 | #include <boost/hana/accessors.hpp> | |
16 | #include <boost/hana/concept/struct.hpp> | |
17 | #include <boost/hana/config.hpp> | |
18 | #include <boost/hana/core/dispatch.hpp> | |
19 | #include <boost/hana/second.hpp> | |
20 | #include <boost/hana/transform.hpp> | |
21 | ||
22 | ||
23 | BOOST_HANA_NAMESPACE_BEGIN | |
24 | //! @cond | |
25 | template <typename Object> | |
26 | constexpr auto members_t::operator()(Object&& object) const { | |
27 | using S = typename hana::tag_of<Object>::type; | |
28 | using Members = BOOST_HANA_DISPATCH_IF(members_impl<S>, | |
29 | hana::Struct<S>::value | |
30 | ); | |
31 | ||
32 | #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS | |
33 | static_assert(hana::Struct<S>::value, | |
34 | "hana::members(object) requires 'object' to be a Struct"); | |
35 | #endif | |
36 | ||
37 | return Members::apply(static_cast<Object&&>(object)); | |
38 | } | |
39 | //! @endcond | |
40 | ||
41 | namespace struct_detail { | |
42 | template <typename Holder, typename Forward> | |
43 | struct members_helper { | |
44 | Holder object; | |
45 | template <typename Accessor> | |
46 | constexpr decltype(auto) operator()(Accessor&& accessor) const { | |
47 | return hana::second(static_cast<Accessor&&>(accessor))( | |
48 | static_cast<Forward>(object) | |
49 | ); | |
50 | } | |
51 | }; | |
52 | } | |
53 | ||
54 | template <typename S, bool condition> | |
55 | struct members_impl<S, when<condition>> : default_ { | |
56 | template <typename Object> | |
57 | static constexpr auto apply(Object&& object) { | |
58 | return hana::transform(hana::accessors<S>(), | |
59 | struct_detail::members_helper<Object&, Object&&>{object} | |
60 | ); | |
61 | } | |
62 | }; | |
63 | BOOST_HANA_NAMESPACE_END | |
64 | ||
65 | #endif // !BOOST_HANA_MEMBERS_HPP |