[libcxx-commits] [PATCH] D131395: [libc++] Implement `lexicographical_compare_three_way`
Adrian Vogelsgesang via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 16 11:23:35 PDT 2022
avogelsgesang added inline comments.
================
Comment at: libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way.pass.cpp:62
+}
+
+constexpr bool test() {
----------------
philnik wrote:
> 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>);
> ```
Thanks for that example! I was able to use this for `lexicographical_compare_three_way_comp.pass.cpp`.
However, I am still struggling to understand what you want to me to change in this file, i.e. `lexicographical_compare_three_way.pass.cpp` where we don't pass a comparator.
What I could come up with so far is:
```
template <class T>
concept has_lexicographical_compare = requires (T t) { std::lexicographical_compare_three_way(std::declval<T*>(), std::declval<T*>(), std::declval<T*>(), std::declval<T*>()); };
// Test that `std::lexicographical_compare_three_way` accepts valid types
static_assert(has_lexicographical_compare<int>);
static_assert(has_lexicographical_compare<WeakInt>);
static_assert(has_lexicographical_compare<PartialInt>);
// Test that `std::lexicographical_compare_three_way` rejects invalid types
static_assert(!has_lexicographical_compare<UnexpectedlyComparableInt>);
static_assert(!has_lexicographical_compare<UncomparableInt>);
```
However that led to the error
```
In file included from /home/tsi/avogelsgesang/Documents/llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way.pass.cpp:18:
In file included from /home/tsi/avogelsgesang/Documents/llvm-project/build/include/c++/v1/algorithm:1771:
/home/tsi/avogelsgesang/Documents/llvm-project/build/include/c++/v1/__algorithm/lexicographical_compare_three_way.h:71:10: error: no matching function for call to 'lexicographical_compare_three_way' return std::lexicographical_compare_three_way(__first1, __last1, __first2, __last2, compare_three_way()); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
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