mystor / rust-cpp

Embed C++ directly inside your rust code!
Apache License 2.0
798 stars 44 forks source link

Allow to derive PartialEq, PartialOrd and Ord for types in cpp_class #38

Closed ogoffart closed 6 years ago

ogoffart commented 6 years ago

So we can do

cpp_class(#[derive(PartialOrd, Ord, PartialEq, Eq)] unsafe struct MyClass as "MyClass" ) 

And these trait are implemented to call the operator ==, or <.

Note that contrary to Clone and Default, which are automatically implemented, these are explicit. The reason why one need to explicitly declare them is that the C++ operators might not have the right semantic for the traits. Else, we could do it automatically, using SFINAE to detect if a==b

The question is weather one should change the Clone and Default trait to be also explicit? I think it is fine that it is automatic since this is almost always what one wants.