none.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*!
  2. @file
  3. Defines `boost::hana::none`.
  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_NONE_HPP
  9. #define BOOST_HANA_NONE_HPP
  10. #include <boost/hana/fwd/none.hpp>
  11. #include <boost/hana/concept/searchable.hpp>
  12. #include <boost/hana/config.hpp>
  13. #include <boost/hana/core/dispatch.hpp>
  14. #include <boost/hana/functional/id.hpp>
  15. #include <boost/hana/none_of.hpp>
  16. BOOST_HANA_NAMESPACE_BEGIN
  17. //! @cond
  18. template <typename Xs>
  19. constexpr auto none_t::operator()(Xs&& xs) const {
  20. using S = typename hana::tag_of<Xs>::type;
  21. using None = BOOST_HANA_DISPATCH_IF(none_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::none(xs) requires 'xs' to be a Searchable");
  27. #endif
  28. return None::apply(static_cast<Xs&&>(xs));
  29. }
  30. //! @endcond
  31. template <typename S, bool condition>
  32. struct none_impl<S, when<condition>> : default_ {
  33. template <typename Xs>
  34. static constexpr auto apply(Xs&& xs)
  35. { return hana::none_of(static_cast<Xs&&>(xs), hana::id); }
  36. };
  37. BOOST_HANA_NAMESPACE_END
  38. #endif // !BOOST_HANA_NONE_HPP