 <p>Bjarne Stroustrup has a short paper called <a href="http://www.research.att.com/~bs/abstraction.pdf" rel="nofollow noreferrer">Abstraction, libraries, and efficiency in C++</a> where he mentions techniques used to achieve what you're looking for. Specifically, he mentions the library <a href="http://www.oonumerics.org/blitz/" rel="nofollow noreferrer">Blitz++</a>, a library for scientific calculations that also has efficient operations for matrices, along with some other interesting libraries. Also, I recommend reading <a href="http://www.artima.com/intv/abstreffi.html" rel="nofollow noreferrer">a conversation with Bjarne Stroustrup on artima.com</a> on that subject.</p>