1 // Copyright (C) 2016-2018 T. Zachary Laine 2 // 3 // Distributed under the Boost Software License, Version 1.0. (See 4 // accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 #include <boost/yap/expression.hpp> 7 8 #include <boost/test/minimal.hpp> 9 10 11 template<typename T> 12 using term = boost::yap::terminal<boost::yap::expression, T>; 13 14 template<typename T> 15 using ref = boost::yap::expression_ref<boost::yap::expression, T>; 16 17 namespace yap = boost::yap; 18 namespace bh = boost::hana; 19 20 test_main(int,char * [])21int test_main(int, char * []) 22 { 23 { 24 term<int> number = {{42}}; 25 26 auto fn = yap::make_expression_function(number); 27 auto fn_copy = fn; 28 29 BOOST_CHECK(fn() == 42); 30 BOOST_CHECK(fn_copy() == 42); 31 32 yap::value(number) = 21; 33 34 BOOST_CHECK(fn() == 21); 35 BOOST_CHECK(fn_copy() == 21); 36 } 37 38 { 39 term<int> number = {{42}}; 40 41 auto fn = yap::make_expression_function(std::move(number)); 42 auto fn_copy = fn; 43 44 BOOST_CHECK(fn() == 42); 45 BOOST_CHECK(fn_copy() == 42); 46 47 yap::value(number) = 21; 48 49 BOOST_CHECK(fn() == 42); 50 BOOST_CHECK(fn_copy() == 42); 51 } 52 53 { 54 term<std::unique_ptr<int>> number = { 55 {std::unique_ptr<int>(new int(42))}}; 56 57 auto fn = yap::make_expression_function(std::move(number)); 58 59 BOOST_CHECK(*fn() == 42); 60 61 auto fn_2 = std::move(fn); 62 BOOST_CHECK(*fn_2() == 42); 63 64 yap::value(number) = std::unique_ptr<int>(new int(21)); 65 66 BOOST_CHECK(*fn_2() == 42); 67 } 68 69 return 0; 70 } 71