File indexing completed on 2025-01-18 09:38:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_FOR_EACH_HPP
0011 #define BOOST_HANA_FOR_EACH_HPP
0012
0013 #include <boost/hana/fwd/for_each.hpp>
0014
0015 #include <boost/hana/concept/foldable.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/unpack.hpp>
0019
0020
0021 namespace boost { namespace hana {
0022
0023 template <typename Xs, typename F>
0024 constexpr void for_each_t::operator()(Xs&& xs, F&& f) const {
0025 using S = typename hana::tag_of<Xs>::type;
0026 using ForEach = BOOST_HANA_DISPATCH_IF(for_each_impl<S>,
0027 hana::Foldable<S>::value
0028 );
0029
0030 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0031 static_assert(hana::Foldable<S>::value,
0032 "hana::for_each(xs, f) requires 'xs' to be Foldable");
0033 #endif
0034
0035 return ForEach::apply(static_cast<Xs&&>(xs), static_cast<F&&>(f));
0036 }
0037
0038
0039 namespace detail {
0040 template <typename F>
0041 struct on_each {
0042 F f;
0043 template <typename ...Xs>
0044 constexpr void operator()(Xs&& ...xs) const {
0045 using Swallow = int[];
0046 (void)Swallow{0, ((void)(*f)(static_cast<Xs&&>(xs)), 0)...};
0047 }
0048 };
0049 }
0050
0051 template <typename T, bool condition>
0052 struct for_each_impl<T, when<condition>> : default_ {
0053 template <typename Xs, typename F>
0054 static constexpr void apply(Xs&& xs, F&& f) {
0055
0056 hana::unpack(static_cast<Xs&&>(xs),
0057 detail::on_each<decltype(&f)>{&f});
0058 }
0059 };
0060 }}
0061
0062 #endif