monad.cpp 780 B

1234567891011121314151617181920212223
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/assert.hpp>
  5. #include <boost/hana/chain.hpp>
  6. #include <boost/hana/config.hpp>
  7. #include <boost/hana/equal.hpp>
  8. #include <boost/hana/flatten.hpp>
  9. #include <boost/hana/optional.hpp>
  10. namespace hana = boost::hana;
  11. int main() {
  12. BOOST_HANA_CONSTEXPR_LAMBDA auto inc = [](auto x) {
  13. return hana::just(x + 1);
  14. };
  15. BOOST_HANA_CONSTEXPR_CHECK(hana::chain(hana::just(1), inc) == hana::just(2));
  16. BOOST_HANA_CONSTANT_CHECK(hana::chain(hana::nothing, inc) == hana::nothing);
  17. BOOST_HANA_CONSTEXPR_CHECK(hana::flatten(hana::just(hana::just(2))) == hana::just(2));
  18. }