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::find`.
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_FIND_HPP
0011 #define BOOST_HANA_FIND_HPP
0012 
0013 #include <boost/hana/fwd/find.hpp>
0014 
0015 #include <boost/hana/concept/searchable.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/equal.hpp>
0019 #include <boost/hana/find_if.hpp>
0020 
0021 
0022 namespace boost { namespace hana {
0023     //! @cond
0024     template <typename Xs, typename Key>
0025     constexpr auto find_t::operator()(Xs&& xs, Key const& key) const {
0026         using S = typename hana::tag_of<Xs>::type;
0027         using Find = BOOST_HANA_DISPATCH_IF(find_impl<S>,
0028             hana::Searchable<S>::value
0029         );
0030 
0031     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0032         static_assert(hana::Searchable<S>::value,
0033         "hana::find(xs, key) requires 'xs' to be Searchable");
0034     #endif
0035 
0036         return Find::apply(static_cast<Xs&&>(xs), key);
0037     }
0038     //! @endcond
0039 
0040     namespace detail {
0041         template <typename T>
0042         struct equal_to {
0043             T const& t;
0044             template <typename U>
0045             constexpr auto operator()(U const& u) const {
0046                 return hana::equal(t, u);
0047             }
0048         };
0049     }
0050 
0051     template <typename S, bool condition>
0052     struct find_impl<S, when<condition>> : default_ {
0053         template <typename Xs, typename Key>
0054         static constexpr auto apply(Xs&& xs, Key const& key) {
0055             return hana::find_if(static_cast<Xs&&>(xs),
0056                                  detail::equal_to<Key>{key});
0057         }
0058     };
0059 }} // end namespace boost::hana
0060 
0061 #endif // !BOOST_HANA_FIND_HPP