Is there a way to generically get the type of a struct, at the top-level in the declaration of said struct, without referring to the actual name of the struct itself?
For example:
#include <type_traits>
struct example {
using attempt1 = example; // <- obvious, but not what I want
using attempt2 = decltype(*this); // <- error
using attempt3 = std::remove_pointer<decltype(this)>::type; // <- error
};
Or:
#include <type_traits>
struct { // anonymous
//using attempt1 = ...;
using attempt2 = decltype(*this);
using attempt3 = std::remove_pointer<decltype(this)>::type;
} x;
Those programs of course fail to compile ("invalid use of 'this' at top level") in C++17 and C++2a mode on GCC 9.x and 10.x, but I'd like to do something like attempt2 or attempt3 where I can get the struct's type without referring to its name ("example" in the first case).
Is this possible?
I took a look through <type_traits> but nothing popped out at me, and I couldn't think of where else to look.