Professional Documents
Culture Documents
int main() {
// fails to link and tries to get the address of "Foo::value"!
f(Foo::value);
// works - pass a temporary value
f(+Foo::value);
}
Decay an array to a pointer: The operator also works when you want
to pass two values to a function.
template
void f(T const& a, T const& b);
int main() {
int a[2];
int b[3];
f(a, b); // won't work! different values for "T"!
f(+a, +b); // works! T is "int*" both time
}
5. You must know the id/identity metafunction. Now check out this
usecase for it, which is for non-template cases.
// void (*f)(); // same
id::type *f;
// void (*f(void(*p)()))(int); // same
id::type *f(id::type *p);
// int (*p)[2] = new int[10][2]; // same
id::type *p = new int[10][2];
// void (C::*p)(int) = 0; // same
id::type C::*p = 0;
It helps decrypting C++ declarations greatly!
// boost::identity is pretty much the same
template
struct id { typedef T type; };