monad.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*!
  2. @file
  3. Defines operators for Monads.
  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_DETAIL_OPERATORS_MONAD_HPP
  9. #define BOOST_HANA_DETAIL_OPERATORS_MONAD_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/tag_of.hpp>
  12. #include <boost/hana/fwd/chain.hpp>
  13. #include <type_traits>
  14. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  15. template <typename Tag>
  16. struct monad_operators {
  17. static constexpr bool value = false;
  18. };
  19. namespace operators {
  20. template <typename Xs, typename F, typename = typename std::enable_if<
  21. detail::monad_operators<typename hana::tag_of<Xs>::type>::value
  22. >::type>
  23. constexpr auto operator|(Xs&& xs, F&& f)
  24. { return hana::chain(static_cast<Xs&&>(xs), static_cast<F&&>(f)); }
  25. } // end namespace operators
  26. } BOOST_HANA_NAMESPACE_END
  27. #endif // !BOOST_HANA_DETAIL_OPERATORS_MONAD_HPP