This is the first of several calculator-building examples derived from Proto. This first one just builds lazy expressions with placeholders, and evaluates them. Here we can first see how much C++14-and-later language features help the end user — the Proto version is much, much longer.
#include <boost/yap/expression.hpp> #include <iostream> int main () { using namespace boost::yap::literals; // Displays "5" std::cout << evaluate( 1_p + 2.0, 3.0 ) << std::endl; // Displays "6" std::cout << evaluate( 1_p * 2_p, 3.0, 2.0 ) << std::endl; // Displays "0.5" std::cout << evaluate( (1_p - 2_p) / 2_p, 3.0, 2.0 ) << std::endl; return 0; }