03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.5. BARTON-NACKMAN TRICK 197<br />

};<br />

bracket proxy operator[](int r) const<br />

{<br />

return bracket proxy(static cast(∗this), r);<br />

}<br />

class matrix : public crtp matrix<br />

{<br />

// ...<br />

};<br />

Once we have such a CRTP class we can provide a bracket operator <strong>for</strong> every matrix class with a<br />

binary application operator. In a full-fledged linear algebra package one needs to pay attention<br />

which matrices return references and which are mutable but the approach is as described above.<br />

Several timings have shown that the indirection with the proxy did not create run-time overhead<br />

compared to the direct usage of the binary access operator. Apparently, the compilers optimized<br />

the creation of proxies away in the executables.

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

Saved successfully!

Ooh no, something went wrong!