I have a member function defined in a macro, that member only takes arguments of the same type as the current class. How can I get the current type in the macro?
I'm thinking something along the lines of
#define EQUAL() bool operator==(const decltype(*this)& b)const {return a==b.a;}
struct A{
int a;
EQUAL()
};
however this
isn't allowed to be used in a top level context like that.
Are there any other methods for deducing the current type?
The only other idea I have is to make it a template with a static assert that it is the same but that feels hacky.
#include <type_traits>
#define EQUAL() \
template<typename T>\
bool operator==(const T& b) const { \
static_assert(std::is_same_v<T,std::decay_t<decltype(*this)>>);\
return a==b.a;\
}
struct A{
int a;
EQUAL()
};