count_if.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*!
  2. @file
  3. Forward declares `boost::hana::count_if`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_FWD_COUNT_IF_HPP
  9. #define BOOST_HANA_FWD_COUNT_IF_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Return the number of elements in the structure for which the
  14. //! `predicate` is satisfied.
  15. //! @ingroup group-Foldable
  16. //!
  17. //! Specifically, returns an object of an unsigned integral type, or
  18. //! a `Constant` holding such an object, which represents the number
  19. //! of elements in the structure satisfying the given `predicate`.
  20. //!
  21. //!
  22. //! @param xs
  23. //! The structure whose elements are counted.
  24. //!
  25. //! @param predicate
  26. //! A function called as `predicate(x)`, where `x` is an element of the
  27. //! structure, and returning a `Logical` representing whether `x` should
  28. //! be counted.
  29. //!
  30. //!
  31. //! Example
  32. //! -------
  33. //! @include example/count_if.cpp
  34. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  35. constexpr auto count_if = [](auto&& xs, auto&& predicate) {
  36. return tag-dispatched;
  37. };
  38. #else
  39. template <typename T, typename = void>
  40. struct count_if_impl : count_if_impl<T, when<true>> { };
  41. struct count_if_t {
  42. template <typename Xs, typename Pred>
  43. constexpr auto operator()(Xs&& xs, Pred&& pred) const;
  44. };
  45. constexpr count_if_t count_if{};
  46. #endif
  47. BOOST_HANA_NAMESPACE_END
  48. #endif // !BOOST_HANA_FWD_COUNT_IF_HPP