What are available options to separate different instances of a class at compile time?
I basically want the following code snippet to compile without errors:
struct equal_ret_t {};
struct different_ret_t {};
struct Foo
{
Foo() = default;
// ... add relevant code here
};
constexpr auto eval(Foo const& a, Foo const& b)
{
// return equal_ret_t for same instances,
// different_ret_t for different instances
}
int main()
{
Foo a;
Foo b;
static_assert(std::is_same_v<decltype(eval(a,a)),equal_ret_t>);
static_assert(std::is_same_v<decltype(eval(b,b)),equal_ret_t>);
static_assert(std::is_same_v<decltype(eval(a,b)),different_ret_t>);
}
What is the required code to add to the Foo
class and/or the eval
function?
Are there any solutions approved by the current C++20/23 standard? If not, can the solution made portable across major compilers?