11.07.2015 Views

Understanding C++ Expression Templates - Angelika Langer

Understanding C++ Expression Templates - Angelika Langer

Understanding C++ Expression Templates - Angelika Langer

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

14The Leaftemplate class SimpleDotProduct : public DotProduct {public:SimpleDotProduct (T* a, T* b) :v1(a), v2(b) {}virtual T eval() { return (*v1)*(*v2); }private:T* v1; T* v2;};© Copyright 1995-2000 by <strong>Angelika</strong> <strong>Langer</strong>. All Rights Reserved.http://www.<strong>Angelika</strong><strong>Langer</strong>.com(27)last update: 11/7/2005 ,21:37The code that initiates the recursive evaluation of thecomposite structure:The Clienttemplate T dot(T* a, T* b, size_t dim){ return (dim==1)? SimpleDotProduct(a,b).eval(): CompositeDotProduct(a,b,dim).eval();}int a[4] = {1,100,0,-1};int b[4] = {2,2,2,2};dot(a,b,4);© Copyright 1995-2000 by <strong>Angelika</strong> <strong>Langer</strong>. All Rights Reserved.http://www.<strong>Angelika</strong><strong>Langer</strong>.com(28)last update: 11/7/2005 ,21:37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!