[libcxx-commits] [PATCH] D97176: [libcxx] adds concepts std::equality_comparable[_with]

Christopher Di Bella via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 3 17:52:14 PST 2021


cjdb added inline comments.


================
Comment at: libcxx/test/std/concepts/comparison/types.h:15
+struct boolean {
+  operator bool() const noexcept;
+};
----------------
Quuxplusone wrote:
> Would anything change if this operator were `explicit`? In production code I would expect their `operator bool` to be `explicit`, because all constructors and conversions should always be `explicit` (and for bool conversions in particular, the `explicit` doesn't normally get in the way, because contextual conversion to bool).
Yes. //`boolean-testable`// refines `convertible_to<T, bool>`[1], which requires `T` be both implicitly and explicitly convertible to `bool`. Would you like an `explicit_bool` test as well?

[1]: http://eel.is/c++draft/concept.booleantestable


================
Comment at: libcxx/test/std/concepts/comparison/types.h:85
+
+struct no_neq {
+  friend bool operator==(no_neq, no_neq) noexcept;
----------------
Quuxplusone wrote:
> I'd say `deleted_ne`. This case is (intentionally) non-parallel to the `no_eq` case above.
I intended them to mirror one another, so I'm not sure I understand what you're getting at.


================
Comment at: libcxx/test/std/concepts/comparison/types.h:163
+  bool operator==(one_way_ne const&) const = default;
+  friend bool operator==(one_way_ne, explicit_operators);
+  friend bool operator!=(one_way_ne, explicit_operators) = delete;
----------------
Quuxplusone wrote:
> Should this `==` say `!=`? At a glance, I have //no// idea what the overload set ends up looking like here. Which if that's the point, it needs a comment. ;)
Hmm... good point. I had to stop and think about it for a moment myself, so I agree //some// documentation is necessary (probably a `static_assert` to prove my intentions and code match). The overload set should look like this:
```
bool operator==(one_way_ne const&) const&;
bool operator!=(one_way_ne const&) const&; // generated

bool operator==(one_way_ne, explicit_operators);
bool operator!=(one_way_ne, explicit_operators) = delete;
bool operator==(explicit_operators), one_way_ne); // generated
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97176/new/

https://reviews.llvm.org/D97176



More information about the libcxx-commits mailing list