RAD Studio
Type Specifier decltype (C++0x)

The C++0x standard includes the decltype keyword and operator, which represents the type of an expression. This feature is one of the C++0x features added to C++Builder 2009.

The format of the decltype operator is:

decltype ( expression )

Here are the rules for evaluating decltype(e):

  • If e is an identifier expresson or accessing a class member, decltype(e) is the type of the thing designated by e. If there is no such thing, or if e is the name of a set of overloaded functions so there is ambiguity, decltype(e) is invalid.
  • Otherwise, if e is a function call or invokes an overloaded operator, decltype(e) is the type returned by the function.
  • Otherwise, if e is an lvalue, decltype(e) is a reference to T (T&) where T is the type of e.
  • If none of the other cases apply, decltype(e) is the type of e.

See the embedded contents in the following examples.

const char *namePtr, nameChar;
decltype(namePtr);      // type is const char*
decltype(nameChar);     // type is const char
int& F(void);       
decltype(F());          // type is int&

struct; D {double value; }
const D* d = new D();

decltype(d->value);    // type is double
decltype((d->value));  // type is const double&

double GetValue(int one);
long int GetValue(double d);
decltype(GetValue);     // ill-formed -- ambiguous
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!