is_empty.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*!
  2. @file
  3. Forward declares `boost::hana::is_empty`.
  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_IS_EMPTY_HPP
  9. #define BOOST_HANA_FWD_IS_EMPTY_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Returns whether the iterable is empty.
  14. //! @ingroup group-Iterable
  15. //!
  16. //! Given an `Iterable` `xs`, `is_empty` returns whether `xs` contains
  17. //! no more elements. In other words, it returns whether trying to
  18. //! extract the tail of `xs` would be an error. In the current version
  19. //! of the library, `is_empty` must return an `IntegralConstant` holding
  20. //! a value convertible to `bool`. This is because only compile-time
  21. //! `Iterable`s are supported right now.
  22. //!
  23. //!
  24. //! Example
  25. //! -------
  26. //! @include example/is_empty.cpp
  27. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  28. constexpr auto is_empty = [](auto const& xs) {
  29. return tag-dispatched;
  30. };
  31. #else
  32. template <typename It, typename = void>
  33. struct is_empty_impl : is_empty_impl<It, when<true>> { };
  34. struct is_empty_t {
  35. template <typename Xs>
  36. constexpr auto operator()(Xs const& xs) const;
  37. };
  38. constexpr is_empty_t is_empty{};
  39. #endif
  40. BOOST_HANA_NAMESPACE_END
  41. #endif // !BOOST_HANA_FWD_IS_EMPTY_HPP