empty.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*!
  2. @file
  3. Defines `boost::hana::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_EMPTY_HPP
  9. #define BOOST_HANA_EMPTY_HPP
  10. #include <boost/hana/fwd/empty.hpp>
  11. #include <boost/hana/concept/monad_plus.hpp>
  12. #include <boost/hana/concept/sequence.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <boost/hana/core/make.hpp>
  16. BOOST_HANA_NAMESPACE_BEGIN
  17. //! @cond
  18. template <typename M>
  19. constexpr auto empty_t<M>::operator()() const {
  20. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  21. static_assert(hana::MonadPlus<M>::value,
  22. "hana::empty<M>() requires 'M' to be a MonadPlus");
  23. #endif
  24. using Empty = BOOST_HANA_DISPATCH_IF(empty_impl<M>,
  25. hana::MonadPlus<M>::value
  26. );
  27. return Empty::apply();
  28. }
  29. //! @endcond
  30. template <typename M, bool condition>
  31. struct empty_impl<M, when<condition>> : default_ {
  32. template <typename ...Args>
  33. static constexpr auto apply(Args&& ...) = delete;
  34. };
  35. template <typename S>
  36. struct empty_impl<S, when<Sequence<S>::value>> {
  37. static constexpr auto apply() {
  38. return hana::make<S>();
  39. }
  40. };
  41. BOOST_HANA_NAMESPACE_END
  42. #endif // !BOOST_HANA_EMPTY_HPP