It used to be possible, using some C++ compilers, to check whether a templated type has already been instantiated, so that the following program syntax compiles without error:
template <typename T> struct MyStruct { };
// some magic goes here
int main () {
static_assert(!is_instantiated<MyStruct<int>>(), "failure");
MyStruct<int> a;
static_assert(is_instantiated<MyStruct<int>>(), "failure");
}
The "magic" was in the solution to this question:
Compile time template instantiation check
However - that no longer works (Godbolt.org) with recent GCC and Clang versions. Also, the user who wrote the accepted answer for that question has left SO and will not be updating it...
So, my question: Is it possible to reliably check whether a class/struct template has been instantiated for a certain type?
Notes:
- Looking for a solution using C++11 - not anything later.
- "It's impossible" is a valid answer, but - only if you can justify it.
- Related: This question.
- If it makes it easier, you may assume that the class is possible to instantiate; but it's better if you don't.