// A new example. // In this file we parameterize individual Point functions with a policy. // Compile time parametrization of functions - an alternative to passing function objects at run time. #include #include #include "point.h" #include "norms.cc" // distance_to and less_than as template functions: template double distance_to(const Point& p, const Point& q){ return N::distance_to(p,q); } template bool less_than(const Point& p, const Point& q){ return N::less_than(p,q); } int main(){ using namespace std; double dist; Point p1(1,2), p2(4,11); dist = distance_to(p1,p2); // Parameterizing distance_to with a cout << "Distance: " << dist << endl; // bundle of two functions from HorizontalNorm cout << "Less than? " << (less_than(p1,p2) ? "true" : "false") << // Ditto less_than endl << endl; Point p3(1,2), p4(4,11); dist = distance_to(p1,p2); // Ditto - here parameterizing with Norm cout << "Distance: " << dist << endl; cout << "Less than? " << (less_than(p1,p2) ? "true" : "false") << endl << endl; }