• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/yap.hpp>
7 #include <boost/yap/print.hpp>
8 
9 #include <iostream>
10 
11 #include <cmath>
12 
13 
14 //[ plus_sqrt_term_alias
15     template <typename T>
16     using term = boost::yap::terminal<boost::yap::expression, T>;
17 //]
primer()18 void primer()
19 {
20 //[ plus_sqrt_yap_value
21 //[ plus_sqrt_yap_type
22 //[ plus_sqrt_yap_top_level_1
23     boost::yap::expression<
24         boost::yap::expr_kind::plus,
25         boost::hana::tuple<
26 //]
27 //[ plus_sqrt_yap_lhs
28             boost::yap::expression<
29                 boost::yap::expr_kind::call,
30                 boost::hana::tuple<
31                     boost::yap::expression<
32                         boost::yap::expr_kind::terminal,
33                         boost::hana::tuple<double (*)(double)>
34                     >,
35                     boost::yap::expression<
36                         boost::yap::expr_kind::terminal,
37                         boost::hana::tuple<double>
38                     >
39                 >
40             >,
41 //]
42 //[ plus_sqrt_yap_rhs
43             boost::yap::expression<
44                 boost::yap::expr_kind::terminal,
45                 boost::hana::tuple<float>
46             >
47 //]
48 //[ plus_sqrt_yap_top_level_2
49         >
50     >
51 //]
52 //]
53     yap_expr = term<double (*)(double)>{{std::sqrt}}(3.0) + 8.0f;
54 //]
55 //[ print_plus_sqrt_yap_value
56     print(std::cout, yap_expr);
57 //]
58 }
59 
foo()60 void foo ()
61 {
62 //[ assign_through_terminal
63     int i = 0;
64     auto expr = boost::yap::make_terminal(i) = 42;
65     evaluate(expr);
66     std::cout << i << "\n"; // Prints 42.
67 //]
68 }
69 
70 //[ print_decl
71 struct thing {};
72 //]
73 
print_expr()74 void print_expr ()
75 {
76 //[ print_expr
77 using namespace boost::yap::literals;
78 
79 auto const const_lvalue_terminal_containing_rvalue = boost::yap::make_terminal("lvalue terminal");
80 
81 double const d = 1.0;
82 auto rvalue_terminal_containing_lvalue = boost::yap::make_terminal(d);
83 
84 auto thing_terminal = boost::yap::make_terminal(thing{});
85 
86 auto expr =
87     4_p +
88     std::move(rvalue_terminal_containing_lvalue) * thing_terminal -
89     const_lvalue_terminal_containing_rvalue;
90 //]
91 
92 boost::yap::print(std::cout, expr) << "\n";
93 }
94 
main()95 int main ()
96 {
97     primer();
98 
99     foo();
100 
101     print_expr();
102 
103     return 0;
104 }
105