suffix.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*!
  2. @file
  3. Defines `boost::hana::suffix`.
  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_SUFFIX_HPP
  9. #define BOOST_HANA_SUFFIX_HPP
  10. #include <boost/hana/fwd/suffix.hpp>
  11. #include <boost/hana/chain.hpp>
  12. #include <boost/hana/concept/monad_plus.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <boost/hana/functional/partial.hpp>
  16. #include <boost/hana/lift.hpp>
  17. #include <boost/hana/prepend.hpp>
  18. BOOST_HANA_NAMESPACE_BEGIN
  19. //! @cond
  20. template <typename Xs, typename Sfx>
  21. constexpr auto suffix_t::operator()(Xs&& xs, Sfx&& sfx) const {
  22. using M = typename hana::tag_of<Xs>::type;
  23. using Suffix = BOOST_HANA_DISPATCH_IF(suffix_impl<M>,
  24. hana::MonadPlus<M>::value
  25. );
  26. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  27. static_assert(hana::MonadPlus<M>::value,
  28. "hana::suffix(xs, sfx) requires 'xs' to be a MonadPlus");
  29. #endif
  30. return Suffix::apply(static_cast<Xs&&>(xs), static_cast<Sfx&&>(sfx));
  31. }
  32. //! @endcond
  33. template <typename M, bool condition>
  34. struct suffix_impl<M, when<condition>> : default_ {
  35. template <typename Xs, typename Z>
  36. static constexpr auto apply(Xs&& xs, Z&& z) {
  37. return hana::chain(static_cast<Xs&&>(xs),
  38. hana::partial(hana::prepend, hana::lift<M>(static_cast<Z&&>(z))));
  39. }
  40. };
  41. BOOST_HANA_NAMESPACE_END
  42. #endif // !BOOST_HANA_SUFFIX_HPP