--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/544de10d-be39-4c83-a211-b888a34724c3%40isocpp.org.
Your strongest argument was about == and != being potentially faster, and that has already been changed (ie: EWG approved. I don't believe CWG has approved wording), pursuant to P1190 and P1185.
I find most of the rest of your arguments to be specious and highly opinionated with little factual basis behind them.
I was particularly amused by your argument that the "average C++ developer" cannot be expected to be able to learn about anything within the standard library's namespace.
Also, performance is not really the reason for `<=>`; it's convenience, consistency, and ease of use without sacrificing performance. So the fact that nobody can prove that `<=>` is undeniably faster in some case not really relevant. So long as it isn't slower, it's a net-gain.
Oh, and as for real code that is more readable with `<=>` than without it, just look at any implementation of `std::optional`.
[...]
Oh, and as for real code that is more readable with `<=>` than without it, just look at any implementation of `std::optional`.
template <typename T>
class optional {
template <ThreeWayComparableWith<T> U>
compare_3way_type_t<T,U> operator<=>(optional<U> const& rhs) const;
{
if (has_value() && rhs.has_value()) {
return **this <=> *rhs;
} else {
return has_value() <=> rhs.has_value();
}
}
};
Sender notified by Mailtrack 02/18/19, 2:58:57 PM |
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/544de10d-be39-4c83-a211-b888a34724c3%40isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAN0NuG5ao9MVQ3wQEgsA%2B52Rucz704Pi-PyK707_npxeoMtXgg%40mail.gmail.com.
Personally I don't think we really need `<=>` as it can easily simulated with some TypeClass based Meta Programming.In fact, I believe it's a technique that is underused in the C++ community.
Here an example of this approach: https://godbolt.org/z/2IIXlh
Maybe we should standardize a set of Type-Classes and Customization Points instead?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/c4244615-6097-4d4c-a87a-4b435911b8a5%40isocpp.org.
#include <iostream>
#include <compare>
int main()
{
auto a = 75;
auto b = 175;
if (auto comp = a <=> b; comp > 0)
std::cout << "greater\n";
else if (comp == 0)
std::cout << "equal\n";
else
std::cout << "lesser\n";
}
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f699812c-8fc6-4080-9eaa-0ff339fc2917%40isocpp.org.
class C{
public:
default operator: <,<=, ==, !=,>=,>;
private:
std::string a,b;
int c;
};
// option 1
bool operator<=(C const& lhs, C const& rhs) {
return lhs < rhs || lhs == rhs;
}
// option 2
bool operator<=(C const& lhs, C const& rhs) {
return !(rhs < lhs);
}
On Saturday, February 16, 2019 at 3:43:01 PM UTC-6, libb...@gmail.com wrote:
<=> will be in C++20
But what does <= do? You have two choices:
Why do you not just use member's <=?Which do you pick?
On Mon, Feb 25, 2019 at 2:40 PM Barry Revzin <barry....@gmail.com> wrote:On Saturday, February 16, 2019 at 3:43:01 PM UTC-6, libb...@gmail.com wrote:<=> will be in C++20Disappointed, not surprised. :)Why do you not just use member's <=?But what does <= do? You have two choices:Which do you pick?
If you do not want to bother answering since this is futile discussion that is also fine. :)Also one more thing I realized rather recently(it is not in the document) but may be relevant for C++26 so I wonder if you could give opinion.When Herb does his thing with reflection (C++26?) spaceship will be kind of suboptimal because people will want to reflect on members andbe able to specify that first you compared cheap members(this can be guessed by type) or based on some knowledge of usage, for example int room_number_ has high entropy in use so use that member first.
auto operator<=>(Type const& rhs) const {
constexpr vector<meta::info> members = get_sorted_members_for_comparison();
for ... (constexpr meta::info member : members) {
auto cmp = this->idexpr(member) <=> rhs.idexpr(member);
if (cmp != 0) {
return cmp;
}
}
return strong_ordering::equal;
}
On Friday, March 1, 2019 at 10:47:41 AM UTC-6, Ivan Matek wrote:On Mon, Feb 25, 2019 at 2:40 PM Barry Revzin <barry....@gmail.com> wrote:On Saturday, February 16, 2019 at 3:43:01 PM UTC-6, libb...@gmail.com wrote:<=> will be in C++20Disappointed, not surprised. :)Why do you not just use member's <=?But what does <= do? You have two choices:Which do you pick?You can do. It just means that if you're a type that provides something other than lexicographic, member-wise comparison, you have to write both < and <= (in addition to ==). Whichever way you go about doing (which typically will just be <= just invoking <), that still seems worse than just being able to write one <=>.The only real benefit of this approach vs the <=> we have in C++20 is slightly shorter defaulting of comparisons? That doesn't seem like a good tradeoff when comparing the two options.
default operator: <, <=, ==, !=, >=, >; // proposed hereauto operator<=>(C const&) const = default; // C++20
The only real benefit of this approach vs the <=> we have in C++20 is slightly shorter defaulting of comparisons? That doesn't seem like a good tradeoff when comparing the two options.
I don't see at all how this makes spaceship "suboptimal". The defaulted <=> won't do what you want, but that doesn't prevent you from writing a non-defaulted <=>. But writing these kinds of comparisons using <=> is still much easier than without <=>:
auto operator<=>(Type const& rhs) const
= my_meta_fn(room_number_, ...);On Fri, Mar 1, 2019 at 8:31 PM Barry Revzin <barry....@gmail.com> wrote:The only real benefit of this approach vs the <=> we have in C++20 is slightly shorter defaulting of comparisons? That doesn't seem like a good tradeoff when comparing the two options.Also return types differ.
And people make fun of me for this, but I really do feel this is confusing to average C++ developer, and that confusion is not worth the benefits.
I don't see at all how this makes spaceship "suboptimal". The defaulted <=> won't do what you want, but that doesn't prevent you from writing a non-defaulted <=>. But writing these kinds of comparisons using <=> is still much easier than without <=>:It is suboptimal because you are writing logic instead of doing something in a declarative way.
I mean your code is nice because you have for each member so code is less fragile than if it was listing every member by name, but for something so common I would hope for language support for declarative way of doing that.
Or at least a way to write something declarative using reflection.In other words I would like to have a way to write a metafunction(or how do you want to call it) that I can use like thisauto operator<=>(Type const& rhs) const
= my_meta_fn(room_number_, ...);In other words my_meta_fn creates the function based on arguments(room_number_,....) (and implicit T argument) and then that function is assigned to the operator <=>.