// CS 509 - Advanced Programming II
// Spring 2004
//
// An example of using expression templates with value-passing evaluation.
#include <iostream>
#include <functional>
#include "ettl.h"
def_binexp(-, minus)
def_binexp(+, plus)
def_binexp(/, divides)
def_binexp(*, multiplies)
template < class Expression >
static result_type
find_max(Expression expr, double l, double r, double s) {
result_type mx = expr.evaluate(l);
while (l < r) {
mx = std::max(expr.evaluate(l), mx);
l += s;
}
return mx;
}
int
main() {
variable x;
std::cout << find_max((x - 3)*(x - 5), 1, 10, 1) << "\n";
std::cout << find_max((x - 3)/(x + 5), 1, 10, 1) << "\n";
}
// $Log: et-lambda.cc,v $
// Revision 1.1 2004/05/06 19:43:14 rclayton
// Initial revision
//
syntax highlighted by Code2HTML, v. 0.9