Skip to content

How to compare tow proxy objects? #227

Answered by mingxwa
xuruilong100 asked this question in Q&A
Discussion options

You must be logged in to vote

@xuruilong100 By design, proxy is not equality comparable. If you want to remove an element from a std::vector<pro::proxy<>>, you need to implement a mechanism to find the index.

The implementation of == in Java or C# simply compares the address of two objects. If this is what you want, simply write add_convention<pro::operator_dispatch<"&">, const void*() const noexcept> when building facade EventComponent, then std::erase_if(events, [addr = &*event2](auto& p) { return &*p == addr; }) should work. (Note that std::remove won't actually shrink the vector).

If you want to compare the value of two objects, RTTI or other techniques should be used depending on your actual requirements.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mingxwa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants