]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/hana/fwd/index_if.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / hana / fwd / index_if.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::index_if`.
4
5 @copyright Louis Dionne 2013-2017
6 @copyright Jason Rice 2017
7 Distributed under the Boost Software License, Version 1.0.
8 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
9 */
10
11 #ifndef BOOST_HANA_FWD_INDEX_IF_HPP
12 #define BOOST_HANA_FWD_INDEX_IF_HPP
13
14 #include <boost/hana/config.hpp>
15 #include <boost/hana/core/when.hpp>
16
17
18 BOOST_HANA_NAMESPACE_BEGIN
19 //! Finds the value associated to the first key satisfying a predicate.
20 //! @ingroup group-Iterable
21 //!
22 //! Given an `Iterable` structure `xs` and a predicate `pred`,
23 //! `index_if(xs, pred)` returns a `hana::optional` containing an `IntegralConstant`
24 //! of the index of the first element that satisfies the predicate or nothing
25 //! if no element satisfies the predicate.
26 //!
27 //!
28 //! @param xs
29 //! The structure to be searched.
30 //!
31 //! @param predicate
32 //! A function called as `predicate(x)`, where `x` is an element of the
33 //! `Iterable` structure and returning whether `x` is the element being
34 //! searched for. In the current version of the library, the predicate
35 //! has to return an `IntegralConstant` holding a value that can be
36 //! converted to `bool`.
37 //!
38 //!
39 //! Example
40 //! -------
41 //! @include example/index_if.cpp
42 #ifdef BOOST_HANA_DOXYGEN_INVOKED
43 constexpr auto index_if = [](auto&& xs, auto&& predicate) {
44 return tag-dispatched;
45 };
46 #else
47 template <typename S, typename = void>
48 struct index_if_impl : index_if_impl<S, when<true>> { };
49
50 struct index_if_t {
51 template <typename Xs, typename Pred>
52 constexpr auto operator()(Xs&& xs, Pred&& pred) const;
53 };
54
55 constexpr index_if_t index_if{};
56 #endif
57 BOOST_HANA_NAMESPACE_END
58
59 #endif // !BOOST_HANA_FWD_INDEX_IF_HPP
60