Skip to content

Instantly share code, notes, and snippets.

@daniel-j-h
Last active August 29, 2015 14:17
Show Gist options
  • Save daniel-j-h/41d6a0423bf999a8c7b6 to your computer and use it in GitHub Desktop.
Save daniel-j-h/41d6a0423bf999a8c7b6 to your computer and use it in GitHub Desktop.
CompileTimeType: force compiler to show you inferred types
// See: EMC++, Item 4
template<typename>
class CompileTimeType;
int main() {
int x;
CompileTimeType<decltype(x)> x_Type;
// cttype.cc:7:32: error: implicit instantiation of undefined template 'CompileTimeType<int>'
// CompileTimeType<decltype(x)> x_Type; ^^^^^
CompileTimeType<decltype((x))> xb_Type;
// cttype.cc:8:34: error: implicit instantiation of undefined template 'CompileTimeType<int &>'
// CompileTimeType<decltype((x))> xb_Type; ^^^^^^^
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment