]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/lazy/monad.cpp
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)
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/chain.hpp>
7 #include <boost/hana/eval.hpp>
8 #include <boost/hana/lazy.hpp>
13 namespace hana
= boost::hana
;
17 T
read_(std::istream
& stream
) {
20 std::cout
<< "read " << x
<< " from the stream\n";
28 std::cout
<< "creating the monadic chain...\n";
29 auto out
= hana::make_lazy(read_
<int>)(std::ref(ss
))
31 std::cout
<< "performing x + 1...\n";
32 return hana::make_lazy(x
+ 1);
35 std::cout
<< "performing x / 2...\n";
36 return hana::make_lazy(x
/ 2);
39 std::cout
<< "putting " << in
<< " in the stream...\n";
40 ss
<< in
; // nothing is evaluated yet
42 std::cout
<< "evaluating the monadic chain...\n";
43 auto eout
= hana::eval(out
);
45 std::cout
<< "the result of the monadic chain is " << eout
<< "\n";
46 BOOST_HANA_RUNTIME_CHECK(eout
== (in
+ 1) / 2);