Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:52:46

0001 /*!
0002 @file
0003 Defines `boost::hana::detail::first_unsatisfied_index`.
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_DETAIL_FIRST_UNSATISFIED_INDEX_HPP
0011 #define BOOST_HANA_DETAIL_FIRST_UNSATISFIED_INDEX_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/integral_constant.hpp>
0015 #include <boost/hana/value.hpp>
0016 
0017 #include <utility>
0018 
0019 
0020 namespace boost { namespace hana { namespace detail {
0021     template <bool, typename Pred, typename ...Xs>
0022     struct find_tail_size;
0023 
0024     template <typename Pred, typename X, typename ...Xs>
0025     struct find_tail_size<true, Pred, X, Xs...> {
0026         static constexpr int value = find_tail_size<
0027             static_cast<bool>(hana::value<decltype(std::declval<Pred>()(std::declval<X>()))>()),
0028             Pred, Xs...
0029         >::value;
0030     };
0031 
0032     template <typename Pred>
0033     struct find_tail_size<true, Pred> {
0034         static constexpr int value = -1;
0035     };
0036 
0037     template <typename Pred, typename ...Xs>
0038     struct find_tail_size<false, Pred, Xs...> {
0039         static constexpr int value = sizeof...(Xs);
0040     };
0041 
0042     //! @ingroup group-details
0043     //! Returns the index of the first element which does not satisfy `Pred`,
0044     //! or `sizeof...(Xs)` if no such element exists.
0045     template <typename Pred>
0046     struct first_unsatisfied_index {
0047         template <typename ...Xs>
0048         constexpr auto operator()(Xs&& ...) const {
0049             return hana::size_c<
0050                 sizeof...(Xs) - 1 - find_tail_size<true, Pred, Xs&&...>::value
0051             >;
0052         }
0053     };
0054 } }} // end namespace boost::hana
0055 
0056 #endif // !BOOST_HANA_DETAIL_FIRST_UNSATISFIED_INDEX_HPP