Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:02

0001 /*!
0002 @file
0003 Defines `boost::hana::for_each`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
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     //! @cond
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     //! @endcond
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             // We use a pointer instead of a reference to avoid a Clang ICE.
0056             hana::unpack(static_cast<Xs&&>(xs),
0057                          detail::on_each<decltype(&f)>{&f});
0058         }
0059     };
0060 }} // end namespace boost::hana
0061 
0062 #endif // !BOOST_HANA_FOR_EACH_HPP