How to compare tow proxy objects? #227
-
pro::proxy<EventComponent> event0 = ...;
pro::proxy<EventComponent> event1 = ...;
pro::proxy<EventComponent> event2 = ...;
std::vector<pro::proxy<EventComponent>> events;
auto it = std::remove(events.begin(), events.end(), event1);
events.erase(it, events.end()); The compiler tells me that my code is illegal, and So, how to compare two |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@xuruilong100 By design, The implementation of If you want to compare the value of two objects, RTTI or other techniques should be used depending on your actual requirements. |
Beta Was this translation helpful? Give feedback.
@xuruilong100 By design,
proxy
is not equality comparable. If you want to remove an element from astd::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 writeadd_convention<pro::operator_dispatch<"&">, const void*() const noexcept>
when building facadeEventComponent
, thenstd::erase_if(events, [addr = &*event2](auto& p) { return &*p == addr; })
should work. (Note thatstd::remove
won't actually shrink thevector
).If you want to compare the value of two objects, RTTI or other techniques should be used depending on your actual requirements.