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 //[ calc2a 7 #include <boost/yap/expression.hpp> 8 9 #include <iostream> 10 11 main()12int main () 13 { 14 using namespace boost::yap::literals; 15 16 auto expr_1 = 1_p + 2.0; 17 18 auto expr_1_fn = [expr_1](auto &&... args) { 19 return evaluate(expr_1, args...); 20 }; 21 22 auto expr_2 = 1_p * 2_p; 23 24 auto expr_2_fn = [expr_2](auto &&... args) { 25 return evaluate(expr_2, args...); 26 }; 27 28 auto expr_3 = (1_p - 2_p) / 2_p; 29 30 auto expr_3_fn = [expr_3](auto &&... args) { 31 return evaluate(expr_3, args...); 32 }; 33 34 // Displays "5" 35 std::cout << expr_1_fn(3.0) << std::endl; 36 37 // Displays "6" 38 std::cout << expr_2_fn(3.0, 2.0) << std::endl; 39 40 // Displays "0.5" 41 std::cout << expr_3_fn(3.0, 2.0) << std::endl; 42 43 return 0; 44 } 45 //] 46