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 
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/eval.hpp>
7 #include <boost/hana/extend.hpp>
8 #include <boost/hana/extract.hpp>
9 #include <boost/hana/lazy.hpp>
10 
11 #include <functional>
12 #include <istream>
13 #include <sstream>
14 namespace hana = boost::hana;
15 
16 
17 template <typename T>
read_one(std::istream & s)18 T read_one(std::istream& s) {
19     T value;
20     s >> value;
21     return value;
22 }
23 
main()24 int main() {
25     std::stringstream s;
26     s << "1 2 3";
27 
28     auto from_stream = hana::extend(hana::make_lazy(read_one<int>)(std::ref(s)), [](auto i) {
29         return hana::eval(i) + 1;
30     });
31 
32     BOOST_HANA_RUNTIME_CHECK(hana::extract(from_stream) == 2);
33     BOOST_HANA_RUNTIME_CHECK(hana::extract(from_stream) == 3);
34     BOOST_HANA_RUNTIME_CHECK(hana::extract(from_stream) == 4);
35 }
36