<s>
Expression	B-Application
templates	I-Application
are	O
a	O
C++	B-Language
template	B-Language
metaprogramming	I-Language
technique	O
that	O
builds	O
structures	O
representing	O
a	O
computation	O
at	O
compile	O
time	O
,	O
where	O
expressions	O
are	O
evaluated	O
only	O
as	O
needed	O
to	O
produce	O
efficient	O
code	O
for	O
the	O
entire	O
computation	O
.	O
</s>
<s>
Expression	B-Application
templates	I-Application
thus	O
allow	O
programmers	O
to	O
bypass	O
the	O
normal	O
order	O
of	O
evaluation	O
of	O
the	O
C++	B-Language
language	I-Language
and	O
achieve	O
optimizations	O
such	O
as	O
loop	O
fusion	O
.	O
</s>
<s>
Expression	B-Application
templates	I-Application
were	O
invented	O
independently	O
by	O
Todd	O
Veldhuizen	O
and	O
David	O
Vandevoorde	O
;	O
it	O
was	O
Veldhuizen	O
who	O
gave	O
them	O
their	O
name	O
.	O
</s>
<s>
They	O
are	O
a	O
popular	O
technique	O
for	O
the	O
implementation	O
of	O
linear	B-Language
algebra	I-Language
software	O
.	O
</s>
<s>
The	O
obvious	O
C++	B-Language
implementation	O
of	O
this	O
operation	O
would	O
be	O
an	O
overloaded	O
operator+	O
that	O
returns	O
a	O
new	O
vector	O
object	O
:	O
</s>
<s>
Delayed	B-Application
evaluation	I-Application
solves	O
this	O
problem	O
,	O
and	O
can	O
be	O
implemented	O
in	O
C++	B-Language
by	O
letting	O
operator+	O
return	O
an	O
object	O
of	O
a	O
custom	O
type	O
,	O
say	O
VecSum	O
,	O
that	O
represents	O
the	O
unevaluated	O
sum	O
of	O
two	O
Vecs	O
,	O
or	O
a	O
vector	O
with	O
a	O
VecSum	O
,	O
etc	O
.	O
</s>
<s>
Expression	B-Application
templates	I-Application
implement	O
delayed	B-Application
evaluation	I-Application
using	O
expression	O
trees	O
that	O
only	O
exist	O
at	O
compile	O
time	O
.	O
</s>
<s>
Example	O
implementation	O
of	O
expression	B-Application
templates	I-Application
:	O
</s>
<s>
An	O
example	O
implementation	O
of	O
expression	B-Application
templates	I-Application
looks	O
like	O
the	O
following	O
.	O
</s>
<s>
It	O
is	O
templated	O
on	O
the	O
actual	O
expression	O
type	O
E	O
to	O
be	O
implemented	O
,	O
per	O
the	O
curiously	B-Language
recurring	I-Language
template	I-Language
pattern	I-Language
.	O
</s>
<s>
The	O
existence	O
of	O
a	O
base	O
class	O
like	O
VecExpression	O
is	O
not	O
strictly	O
necessary	O
for	O
expression	B-Application
templates	I-Application
to	O
work	O
.	O
</s>
<s>
A	O
subtlety	O
intervenes	O
in	O
this	O
case	O
:	O
in	O
order	O
to	O
reference	B-Language
the	O
original	O
data	O
when	O
summing	O
two	O
VecExpressions	O
,	O
VecSum	O
needs	O
to	O
store	O
a	O
const	O
reference	B-Language
to	O
each	O
VecExpressionif	O
it	O
is	O
a	O
leafs	O
,	O
otherwise	O
it	O
is	O
a	O
temporary	O
object	O
that	O
needs	O
to	O
be	O
copied	O
to	O
be	O
properly	O
saved	O
.	O
</s>
<s>
Expression	B-Application
templates	I-Application
have	O
been	O
found	O
especially	O
useful	O
by	O
the	O
authors	O
of	O
libraries	O
for	O
linear	B-Language
algebra	I-Language
,	O
that	O
is	O
,	O
for	O
dealing	O
with	O
vectors	O
and	O
matrices	B-Architecture
of	O
numbers	O
.	O
</s>
<s>
Among	O
libraries	O
employing	O
expression	O
template	O
are	O
Dlib	B-Language
,	O
Armadillo	B-Language
,	O
Blaze	O
,	O
Blitz++	B-Language
,	O
Boost	B-Language
uBLAS	B-Language
,	O
Eigen	B-Language
,	O
POOMA	O
,	O
Stan	B-Application
Math	I-Application
Library	I-Application
,	O
and	O
xtensor	O
.	O
</s>
<s>
Expression	B-Application
templates	I-Application
can	O
also	O
accelerate	O
C++	B-Language
automatic	B-Algorithm
differentiation	I-Algorithm
implementations	O
,	O
as	O
demonstrated	O
in	O
the	O
Adept	B-Language
library	I-Language
.	O
</s>
<s>
Outside	O
of	O
vector	O
math	O
,	O
the	O
Spirit	B-General_Concept
parser	I-General_Concept
framework	I-General_Concept
uses	O
expression	B-Application
templates	I-Application
to	O
represent	O
formal	O
grammars	O
and	O
compile	O
these	O
into	O
parsers	O
.	O
</s>
