any_of.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*!
  2. @file
  3. Defines `boost::hana::detail::any_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_DETAIL_ANY_OF_HPP
  9. #define BOOST_HANA_DETAIL_ANY_OF_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <type_traits>
  12. #include <utility>
  13. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  14. std::false_type expand(...);
  15. template <template <typename ...> class Predicate, typename ...T>
  16. decltype(expand(
  17. typename std::enable_if<!Predicate<T>::value, void*>::type{}...
  18. )) any_of_impl(int);
  19. template <template <typename ...> class Predicate, typename ...T>
  20. std::true_type any_of_impl(...);
  21. //! @ingroup group-details
  22. //! Returns whether the `Predicate` is satisfied by any of the `T...`.
  23. //!
  24. //! This metafunction will short-circuit the evaluation at the first
  25. //! type satisfying the predicate, if such a type exists.
  26. //!
  27. //!
  28. //! @note
  29. //! The implementation technique used here was originally shown to
  30. //! me by Eric Fiselier. All credits where due.
  31. template <template <typename ...> class Predicate, typename ...T>
  32. struct any_of
  33. : decltype(any_of_impl<Predicate, T...>(int{}))
  34. { };
  35. } BOOST_HANA_NAMESPACE_END
  36. #endif // !BOOST_HANA_DETAIL_ANY_OF_HPP