Custom operator== in GoInterface now takes precedence
This commit is contained in:
parent
dcd081e6d3
commit
5de7d757a8
2 changed files with 14 additions and 1 deletions
|
@ -85,6 +85,11 @@ struct GoInterface : Value {
|
||||||
transformer(impl::TryGet<ConstexprString<boost::pfr::get_name<Is, Type>().size() + 1>{boost::pfr::get_name<Is, Type>().begin()}>(other))) && ...);
|
transformer(impl::TryGet<ConstexprString<boost::pfr::get_name<Is, Type>().size() + 1>{boost::pfr::get_name<Is, Type>().begin()}>(other))) && ...);
|
||||||
}(std::make_index_sequence<boost::pfr::tuple_size_v<Value>>());
|
}(std::make_index_sequence<boost::pfr::tuple_size_v<Value>>());
|
||||||
};
|
};
|
||||||
|
template <typename T>
|
||||||
|
inline constexpr auto operator==(T&& other) const -> bool
|
||||||
|
requires (requires(const Value& value){value == other;}) {
|
||||||
|
return static_cast<const Value&>(*this) == other;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace utempl
|
} // namespace utempl
|
||||||
|
|
|
@ -7,6 +7,13 @@ struct SomeInterface {
|
||||||
|
|
||||||
struct SomeStruct {
|
struct SomeStruct {
|
||||||
int field;
|
int field;
|
||||||
|
friend auto operator==(const SomeInterface& a, const SomeStruct& b) -> bool {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SomeStruct2 {
|
||||||
|
int field;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(GoInterface, Basic) {
|
TEST(GoInterface, Basic) {
|
||||||
|
@ -18,5 +25,6 @@ TEST(GoInterface, Equal) {
|
||||||
utempl::GoInterface<SomeInterface> obj(SomeStruct{1});
|
utempl::GoInterface<SomeInterface> obj(SomeStruct{1});
|
||||||
EXPECT_EQ(obj, utempl::GoInterface{SomeInterface{1}});
|
EXPECT_EQ(obj, utempl::GoInterface{SomeInterface{1}});
|
||||||
EXPECT_EQ(obj, SomeInterface{1});
|
EXPECT_EQ(obj, SomeInterface{1});
|
||||||
EXPECT_EQ(obj, SomeStruct{1});
|
EXPECT_NE(obj, SomeStruct{1});
|
||||||
|
EXPECT_EQ(obj, SomeStruct2{1});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue