Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:43:35

0001 /*!
0002 @file
0003 Defines `boost::hana::count`.
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_COUNT_HPP
0011 #define BOOST_HANA_COUNT_HPP
0012 
0013 #include <boost/hana/fwd/count.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/count_if.hpp>
0019 #include <boost/hana/equal.hpp>
0020 
0021 
0022 namespace boost { namespace hana {
0023     //! @cond
0024     template <typename Xs, typename Value>
0025     constexpr auto count_t::operator()(Xs&& xs, Value&& value) const {
0026         using S = typename hana::tag_of<Xs>::type;
0027         using Count = BOOST_HANA_DISPATCH_IF(count_impl<S>,
0028             hana::Foldable<S>::value
0029         );
0030 
0031     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0032         static_assert(hana::Foldable<S>::value,
0033         "hana::count(xs, value) requires 'xs' to be Foldable");
0034     #endif
0035 
0036         return Count::apply(static_cast<Xs&&>(xs), static_cast<Value&&>(value));
0037     }
0038     //! @endcond
0039 
0040     template <typename T, bool condition>
0041     struct count_impl<T, when<condition>> : default_ {
0042         template <typename Xs, typename Value>
0043         static constexpr auto apply(Xs&& xs, Value&& value) {
0044             return hana::count_if(static_cast<Xs&&>(xs),
0045                 hana::equal.to(static_cast<Value&&>(value)));
0046         }
0047     };
0048 }} // end namespace boost::hana
0049 
0050 #endif // !BOOST_HANA_COUNT_HPP