-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hana::less does not work for adapted structs #530
Comments
The compiler error is that your type In any case, you would need to implement EDIT: For the documentation, see EDIT: BTW The |
The segfault is when calling
So, in general, I need to implement hana::less_impl to use hana::less for every struct (hundreds of them I have) in my project, to use hana::less to implement My goal is to use Just for information - I did this to have implementation of operator< and still use ADAPT_STRUCT:
For me, it is hard to believe that adding support for adapted structs in hana::less is so hard, it was done for hana::equal and it just works. But ok, for C++20 it is not needed... |
The only benefits to implementing In general, adapted structs are not considered ordered because it is the user who should opt in and define how that ordering should work. I made a more general solution that uses namespace boost::hana {
template <typename T>
struct less_impl<T, T,
hana::when<demo::concept::LexicographicallyOrderedStruct<T>::value>> {
static constexpr auto apply(demo::Some const& x,
demo::Some const& y) {
constexpr auto accessors = hana::transform(hana::accessors<T>(),
hana::second);
return hana::lexicographical_compare(accessors, accessors,
[&](auto accessor, auto) {
return hana::less(accessor(x), accessor(y));
});
}
};
}
|
Consider this code godbolt
The codebase is c++17 - so I cannot just default compare operators...
For any adapted struct (in hana (actually boost::hana) way) I have this strange situation when
hana::equal
just works for implementingoperator==
whilehana::less
cannot be used for implementingoperator<
. For me documentation is unclear - should it work?I dig a little into this problem - and it seems that when I call directly
hana::less
fromoperator<
thenless
callsoperator<
so infinite recursion - so segfault.While when it is called directly (not via operator<) then it does not compile with a set of static-assert, starting from complaining about adapted struct being not ordered - well...
When I compared sources for
equal
andless
- indeed - support for adapted structs is missing inless
.The code:
The output:
P.S.
I tried also to use hana::lexicographical_compare
- but I did not manage to use it for adapted structs - any help would be welcome. I ended up with using
hana::all_of`...The text was updated successfully, but these errors were encountered: