<s>
In	O
the	O
C++	B-Language
programming	I-Language
language	I-Language
,	O
decltype	B-Language
is	O
a	O
keyword	O
used	O
to	O
query	O
the	O
type	O
of	O
an	O
expression	O
.	O
</s>
<s>
Introduced	O
in	O
C++11	B-Language
,	O
its	O
primary	O
intended	O
use	O
is	O
in	O
generic	B-Language
programming	I-Language
,	O
where	O
it	O
is	O
often	O
difficult	O
,	O
or	O
even	O
impossible	O
,	O
to	O
express	O
types	O
that	O
depend	O
on	O
template	B-Application
parameters	O
.	O
</s>
<s>
As	O
generic	B-Language
programming	I-Language
techniques	O
became	O
increasingly	O
popular	O
throughout	O
the	O
1990s	O
,	O
the	O
need	O
for	O
a	O
type-deduction	O
mechanism	O
was	O
recognized	O
.	O
</s>
<s>
In	O
2002	O
,	O
Bjarne	O
Stroustrup	O
proposed	O
that	O
a	O
standardized	O
version	O
of	O
the	O
operator	O
be	O
added	O
to	O
the	O
C++	B-Language
language	I-Language
,	O
and	O
suggested	O
the	O
name	O
"	O
decltype	B-Language
"	O
,	O
to	O
reflect	O
that	O
the	O
operator	O
would	O
yield	O
the	O
"	O
declared	O
type	O
"	O
of	O
an	O
expression	O
.	O
</s>
<s>
decltype	B-Language
's	O
semantics	O
were	O
designed	O
to	O
cater	O
to	O
both	O
generic	O
library	O
writers	O
and	O
novice	O
programmers	O
.	O
</s>
<s>
Like	O
the	O
sizeof	B-Language
operator	O
,	O
decltype	B-Language
's	O
operand	O
is	O
not	O
evaluated	O
.	O
</s>
<s>
With	O
the	O
introduction	O
of	O
templates	B-Application
into	O
the	O
C++	B-Language
programming	I-Language
language	I-Language
,	O
and	O
the	O
advent	O
of	O
generic	B-Language
programming	I-Language
techniques	O
pioneered	O
by	O
the	O
Standard	B-Application
Template	I-Application
Library	I-Application
,	O
the	O
need	O
for	O
a	O
mechanism	O
for	O
obtaining	O
the	O
type	O
of	O
an	O
expression	O
,	O
commonly	O
referred	O
to	O
as	O
typeof	O
,	O
was	O
recognized	O
.	O
</s>
<s>
In	O
generic	B-Language
programming	I-Language
,	O
it	O
is	O
often	O
difficult	O
or	O
impossible	O
to	O
express	O
types	O
that	O
depend	O
on	O
template	B-Application
parameters	O
,	O
in	O
particular	O
the	O
return	O
type	O
of	O
function	O
template	B-Application
instantiations	O
.	O
</s>
<s>
As	O
early	O
as	O
1997	O
,	O
before	O
C++	B-Language
was	O
fully	O
standardized	O
,	O
Brian	O
Parker	O
proposed	O
a	O
portable	O
solution	O
based	O
on	O
the	O
sizeof	B-Language
operator	O
.	O
</s>
<s>
In	O
an	O
October	O
2000	O
article	O
of	O
Dr.	O
Dobb	O
's	O
Journal	O
,	O
Andrei	O
Alexandrescu	O
remarked	O
that	O
"	O
having	O
a	O
typeof	O
would	O
make	O
much	O
template	B-Application
code	O
easier	O
to	O
write	O
and	O
understand.	O
"	O
</s>
<s>
He	O
also	O
noted	O
that	O
"	O
typeof	O
and	O
sizeof	B-Language
share	O
the	O
same	O
backend	O
,	O
because	O
sizeof	B-Language
has	O
to	O
compute	O
the	O
type	O
anyway.	O
"	O
</s>
<s>
They	O
characterized	O
the	O
use	O
of	O
type	O
conventions	O
,	O
like	O
the	O
typedefs	B-Language
provided	O
by	O
the	O
Standard	B-Application
Template	I-Application
Library	I-Application
,	O
as	O
a	O
more	O
powerful	O
and	O
general	O
technique	O
.	O
</s>
<s>
In	O
a	O
2011	O
article	O
on	O
C++0x	B-Language
,	O
Koenig	O
and	O
Moo	O
predicted	O
that	O
"	O
decltype	B-Language
will	O
be	O
widely	O
used	O
to	O
make	O
everyday	O
programs	O
easier	O
to	O
write.	O
"	O
</s>
<s>
In	O
2002	O
,	O
Bjarne	O
Stroustrup	O
suggested	O
extending	O
the	O
C++	B-Language
language	I-Language
with	O
mechanisms	O
for	O
querying	O
the	O
type	O
of	O
an	O
expression	O
,	O
and	O
initializing	O
objects	O
without	O
specifying	O
the	O
type	O
.	O
</s>
<s>
Stroustrup	O
observed	O
that	O
the	O
reference-dropping	O
semantics	O
offered	O
by	O
the	O
typeof	O
operator	O
provided	O
by	O
the	O
GCC	B-Application
and	O
EDG	B-Language
compilers	O
could	O
be	O
problematic	O
.	O
</s>
<s>
The	O
initial	O
proposal	O
to	O
the	O
C++	B-Language
standards	O
committee	O
outlined	O
a	O
combination	O
of	O
the	O
two	O
variants	O
;	O
the	O
operator	O
would	O
return	O
a	O
reference	O
type	O
only	O
if	O
the	O
declared	O
type	O
of	O
the	O
expression	O
included	O
a	O
reference	O
.	O
</s>
<s>
To	O
emphasize	O
that	O
the	O
deduced	O
type	O
would	O
reflect	O
the	O
"	O
declared	O
type	O
"	O
of	O
the	O
expression	O
,	O
the	O
operator	O
was	O
proposed	O
to	O
be	O
named	O
decltype	B-Language
.	O
</s>
<s>
One	O
of	O
the	O
cited	O
main	O
motivations	O
for	O
the	O
decltype	B-Language
proposal	O
was	O
the	O
ability	O
to	O
write	O
perfect	O
forwarding	O
function	O
templates	B-Application
.	O
</s>
<s>
Without	O
decltype	B-Language
,	O
it	O
is	O
not	O
generally	O
possible	O
to	O
accomplish	O
this	O
.	O
</s>
<s>
decltype	B-Language
is	O
essential	O
here	O
because	O
it	O
preserves	O
the	O
information	O
about	O
whether	O
the	O
wrapped	O
function	O
returns	O
a	O
reference	O
type	O
.	O
</s>
<s>
Similarly	O
to	O
the	O
sizeof	B-Language
operator	O
,	O
the	O
operand	O
of	O
decltype	B-Language
is	O
unevaluated	O
.	O
</s>
<s>
Informally	O
,	O
the	O
type	O
returned	O
by	O
decltype(e )	O
is	O
deduced	O
as	O
follows	O
:	O
</s>
<s>
Otherwise	O
,	O
if	O
e	O
is	O
an	O
lvalue	O
,	O
decltype(e )	O
is	O
T&	O
,	O
where	O
T	O
is	O
the	O
type	O
of	O
e	O
;	O
if	O
e	O
is	O
an	O
xvalue	O
,	O
the	O
result	O
is	O
T&&	O
;	O
otherwise	O
,	O
e	O
is	O
a	O
prvalue	O
and	O
the	O
result	O
is	O
T	O
.	O
</s>
<s>
As	O
a	O
special	O
case	O
,	O
decltype(auto )	O
allows	O
for	O
type	O
deduction	O
like	O
auto	O
but	O
it	O
preserves	O
the	O
value	O
category	O
of	O
the	O
initializer	O
.	O
</s>
<s>
More	O
specifically	O
,	O
it	O
is	O
equivalent	O
to	O
decltype(initializer )	O
.	O
</s>
<s>
These	O
semantics	O
were	O
designed	O
to	O
fulfill	O
the	O
needs	O
of	O
generic	O
library	O
writers	O
,	O
while	O
at	O
the	O
same	O
time	O
being	O
intuitive	O
for	O
novice	O
programmers	O
,	O
because	O
the	O
return	O
type	O
of	O
decltype	B-Language
always	O
matches	O
the	O
type	O
of	O
the	O
object	O
or	O
function	O
exactly	O
as	O
declared	O
in	O
the	O
source	O
code	O
.	O
</s>
<s>
The	O
reason	O
for	O
the	O
difference	O
between	O
the	O
latter	O
two	O
invocations	O
of	O
decltype	B-Language
is	O
that	O
the	O
parenthesized	O
expression	O
(	O
a->x	O
)	O
is	O
neither	O
an	O
id-expression	O
nor	O
a	O
member	O
access	O
expression	O
,	O
and	O
therefore	O
does	O
not	O
denote	O
a	O
named	O
object	O
.	O
</s>
<s>
The	O
fact	O
that	O
extra	O
parentheses	O
introduce	O
a	O
reference	O
qualifier	O
to	O
the	O
type	O
can	O
be	O
a	O
source	O
of	O
errors	O
for	O
programmers	O
who	O
do	O
not	O
fully	O
understand	O
decltype	B-Language
.	O
</s>
<s>
In	O
December	O
2008	O
,	O
a	O
concern	O
was	O
raised	O
to	O
the	O
committee	O
by	O
Jaakko	O
Järvi	O
over	O
the	O
inability	O
to	O
use	O
decltype	B-Language
to	O
form	O
a	O
qualified-id	O
,	O
which	O
is	O
inconsistent	O
with	O
the	O
intent	O
that	O
decltype(e )	O
should	O
be	O
treated	O
"	O
as	O
if	O
it	O
were	O
a	O
typedef-name	O
"	O
.	O
</s>
<s>
While	O
commenting	O
on	O
the	O
formal	O
Committee	O
Draft	O
for	O
C++0x	B-Language
,	O
the	O
Japanese	O
ISO	O
member	O
body	O
noted	O
that	O
"	O
a	O
scope	O
operator( 	O
::	O
)	O
cannot	O
be	O
applied	O
to	O
decltype	B-Language
,	O
but	O
it	O
should	O
be	O
.	O
</s>
<s>
This	O
,	O
and	O
similar	O
issues	O
pertaining	O
to	O
the	O
wording	O
inhibiting	O
the	O
use	O
of	O
decltype	B-Language
in	O
the	O
declaration	O
of	O
a	O
derived	O
class	O
and	O
in	O
a	O
destructor	B-Language
call	O
,	O
were	O
addressed	O
by	O
David	O
Vandevoorde	O
,	O
and	O
voted	O
into	O
the	O
working	O
paper	O
in	O
March	O
2010	O
.	O
</s>
<s>
decltype	B-Language
is	O
included	O
in	O
the	O
C++	B-Language
Language	I-Language
Standard	O
since	O
C++11	B-Language
.	I-Language
</s>
<s>
Microsoft	O
's	O
Visual	B-Application
C++	I-Application
2010	I-Application
and	O
later	O
compilers	O
provide	O
a	O
decltype	B-Language
type	O
specifier	O
that	O
closely	O
mimics	O
the	O
semantics	O
as	O
described	O
in	O
the	O
standards	O
committee	O
proposal	O
.	O
</s>
<s>
It	O
can	O
be	O
used	O
with	O
both	O
managed	B-Language
and	O
native	O
code	O
.	O
</s>
<s>
The	O
documentation	O
states	O
that	O
it	O
is	O
"	O
useful	O
primarily	O
to	O
developers	O
who	O
write	O
template	B-Application
libraries.	O
"	O
</s>
<s>
decltype	B-Language
was	O
added	O
to	O
the	O
mainline	O
of	O
the	O
GCC	B-Application
C++	B-Language
compiler	O
in	O
version	O
4.3	O
,	O
released	O
on	O
March	O
5	O
,	O
2008	O
.	O
decltype	B-Language
is	O
also	O
present	O
in	O
Codegear	O
's	O
C++	B-Language
Builder	I-Language
2009	I-Language
,	O
the	O
Intel	B-Language
C++	I-Language
Compiler	I-Language
,	O
and	O
Clang	B-Application
.	O
</s>
