minimal.cpp 910 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/algorithm.hpp>
  7. #include <array>
  8. #include <iostream>
  9. //[ minimal_template
  10. template <boost::yap::expr_kind Kind, typename Tuple>
  11. struct minimal_expr
  12. {
  13. static const boost::yap::expr_kind kind = Kind;
  14. Tuple elements;
  15. };
  16. //]
  17. int main()
  18. {
  19. //[ minimal_template_manual_construction
  20. auto left = boost::yap::make_terminal<minimal_expr>(1);
  21. auto right = boost::yap::make_terminal<minimal_expr>(41);
  22. auto expr = boost::yap::make_expression<
  23. minimal_expr,
  24. boost::yap::expr_kind::plus
  25. >(left, right);
  26. //]
  27. //[ minimal_template_evaluation
  28. auto result = boost::yap::evaluate(expr);
  29. std::cout << result << "\n"; // prints "42"
  30. //]
  31. return 0;
  32. }