Is it possible to get the "type of current struct" inside struct? For example, I want to do something like this:
struct foobar {
int x, y;
bool operator==(const THIS_TYPE& other) const
{
return x==other.x && y==other.y;
}
}
I tried to do it as follows:
struct foobar {
int x, y;
template<typename T>
bool operator==(const T& t) const
{
decltype (*this)& other = t;
return x==other.x && y==other.y;
}
}
but it looks ugly, requires support for the latest C ++ Standard and compilation of its MSVC compiler (it crashes with an "internal error").
In fact, I just want to write some preprocessor macros to automatically create functions such as operator==:
struct foobar {
int x, y;
GEN_COMPARE_FUNC(x, y);
}
struct some_info {
double len;
double age;
int rank;
GEN_COMPARE_FUNC(len, age, rank);
}
But I need to know the "current type" inside the macro.
qehgt source
share