count.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. @file
  3. Forward declares `boost::hana::count`.
  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_HPP
  9. #define BOOST_HANA_FWD_COUNT_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 that compare equal to
  14. //! a given value.
  15. //! @ingroup group-Foldable
  16. //!
  17. //! Given a Foldable structure `xs` and a value `value`, `count` returns
  18. //! an unsigned integral, or a Constant thereof, representing the number
  19. //! of elements of `xs` that compare equal to `value`. For this method to
  20. //! be well-defined, all the elements of the structure must be Comparable
  21. //! with the given value.
  22. //!
  23. //!
  24. //! @param xs
  25. //! The structure whose elements are counted.
  26. //!
  27. //! @param value
  28. //! A value compared with each element in the structure. Elements
  29. //! that compare equal to this value are counted, others are not.
  30. //!
  31. //!
  32. //! Example
  33. //! -------
  34. //! @include example/count.cpp
  35. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  36. constexpr auto count = [](auto&& xs, auto&& value) {
  37. return tag-dispatched;
  38. };
  39. #else
  40. template <typename T, typename = void>
  41. struct count_impl : count_impl<T, when<true>> { };
  42. struct count_t {
  43. template <typename Xs, typename Value>
  44. constexpr auto operator()(Xs&& xs, Value&& value) const;
  45. };
  46. constexpr count_t count{};
  47. #endif
  48. BOOST_HANA_NAMESPACE_END
  49. #endif // !BOOST_HANA_FWD_COUNT_HPP