all_of.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*!
  2. @file
  3. Defines `boost::hana::all_of`.
  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_ALL_OF_HPP
  9. #define BOOST_HANA_ALL_OF_HPP
  10. #include <boost/hana/fwd/all_of.hpp>
  11. #include <boost/hana/any_of.hpp>
  12. #include <boost/hana/concept/searchable.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <boost/hana/functional/compose.hpp>
  16. #include <boost/hana/not.hpp>
  17. BOOST_HANA_NAMESPACE_BEGIN
  18. //! @cond
  19. template <typename Xs, typename Pred>
  20. constexpr auto all_of_t::operator()(Xs&& xs, Pred&& pred) const {
  21. using S = typename hana::tag_of<Xs>::type;
  22. using AllOf = BOOST_HANA_DISPATCH_IF(all_of_impl<S>,
  23. hana::Searchable<S>::value
  24. );
  25. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  26. static_assert(hana::Searchable<S>::value,
  27. "hana::all_of(xs, pred) requires 'xs' to be a Searchable");
  28. #endif
  29. return AllOf::apply(static_cast<Xs&&>(xs), static_cast<Pred&&>(pred));
  30. }
  31. //! @endcond
  32. template <typename S, bool condition>
  33. struct all_of_impl<S, when<condition>> : default_ {
  34. template <typename Xs, typename Pred>
  35. static constexpr auto apply(Xs&& xs, Pred&& pred) {
  36. return hana::not_(hana::any_of(static_cast<Xs&&>(xs),
  37. hana::compose(hana::not_, static_cast<Pred&&>(pred))));
  38. }
  39. };
  40. BOOST_HANA_NAMESPACE_END
  41. #endif // !BOOST_HANA_ALL_OF_HPP