Detect if a type exists in C++

Viewed 7274

I'd need a template which can be called like this:

int x = type_exists< std::vector<int> >::value;

This should set x to 1 if #include <vector> was present (either explicitly or transitively) earlier in the source, otherwise it should set x to 0.

Is it possible to do it in C++? I'm using GCC, so GCC extensions are also fine.

It's also OK to change the call syntax a bit.

It's not OK to run the C++ compiler twice: first just to figure out if we get a compile error.

2 Answers
Related