any.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*!
  2. @file
  3. Defines `boost::hana::any`.
  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_ANY_HPP
  9. #define BOOST_HANA_ANY_HPP
  10. #include <boost/hana/fwd/any.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/id.hpp>
  16. BOOST_HANA_NAMESPACE_BEGIN
  17. //! @cond
  18. template <typename Xs>
  19. constexpr auto any_t::operator()(Xs&& xs) const {
  20. using S = typename hana::tag_of<Xs>::type;
  21. using Any = BOOST_HANA_DISPATCH_IF(any_impl<S>,
  22. hana::Searchable<S>::value
  23. );
  24. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  25. static_assert(hana::Searchable<S>::value,
  26. "hana::any(xs) requires 'xs' to be a Searchable");
  27. #endif
  28. return Any::apply(static_cast<Xs&&>(xs));
  29. }
  30. //! @endcond
  31. template <typename S, bool condition>
  32. struct any_impl<S, when<condition>> : default_ {
  33. template <typename Xs>
  34. static constexpr auto apply(Xs&& xs)
  35. { return hana::any_of(static_cast<Xs&&>(xs), hana::id); }
  36. };
  37. BOOST_HANA_NAMESPACE_END
  38. #endif // !BOOST_HANA_ANY_HPP