3 Defines `boost::hana::members`.
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)
10 #ifndef BOOST_HANA_MEMBERS_HPP
11 #define BOOST_HANA_MEMBERS_HPP
13 #include <boost/hana/fwd/members.hpp>
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>
23 BOOST_HANA_NAMESPACE_BEGIN
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
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");
37 return Members::apply(static_cast<Object&&>(object));
41 namespace struct_detail {
42 template <typename Holder, typename Forward>
43 struct members_helper {
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)
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}
63 BOOST_HANA_NAMESPACE_END
65 #endif // !BOOST_HANA_MEMBERS_HPP