[libcxx-commits] [PATCH] D131395: [libc++] Implement `lexicographical_compare_three_way`

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Aug 13 04:07:02 PDT 2022


philnik added inline comments.


================
Comment at: libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way.pass.cpp:62
+}
+
+constexpr bool test() {
----------------
avogelsgesang wrote:
> mumbleskates wrote:
> > avogelsgesang wrote:
> > > huixie90 wrote:
> > > > The spec has explicitly specifies the return type ` -> decltype(__comp(*__first1, *__first2))` and this has a SFINAE effect.
> > > > It would be good to test the SFINAE effect as well (if __comp is not callbale then the function should be SFINAEed out)
> > > Sorry, but I don't quite understand this point. How should I check for SFINAE here?
> > in C++20 (which you have the luxury of relying upon since this function is new in C++20) you can just make a concept and then `static_check` it.
> still can't follow. Did you mean `static_assert`? Or is `static_check` something different?
> How would I use a concept to `static_assert` that `std::lexicographical_compare_three_way` is excluded from a function overload set due to SFINAE?
You can do something like
```
template <class T>
concept HasLexicographicalCompare = requires (T whatever) { std::lexicographical_compare_three_way(whatever); };

static_assert(hasLexicographicalCompare<CorrectType>)
static_assert(!HasLexicographicalCompare<IncorrectType>);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131395



More information about the libcxx-commits mailing list