| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
#include <algorithm> |
| 4 |
#include <concepts> |
| 5 |
|
| 6 |
struct Comp |
| 7 |
{ |
| 8 |
constexpr bool operator()(const int&& x, const int&& y) { return x < y; } |
| 9 |
}; |
| 10 |
|
| 11 |
struct Proj |
| 12 |
{ |
| 13 |
constexpr const int&& operator()(const int& x) const { return std::move(x); } |
| 14 |
}; |
| 15 |
|
| 16 |
static_assert(std::indirect_strict_weak_order<Comp, std::projected<const int*, Proj>>); |
| 17 |
|
| 18 |
static_assert(std::ranges::clamp(+1, 0, 2, Comp{}, Proj{}) == 1); |
| 19 |
static_assert(std::ranges::clamp(-1, 0, 2, Comp{}, Proj{}) == 0); |
| 20 |
static_assert(std::ranges::clamp(10, 0, 2, Comp{}, Proj{}) == 2); |
| 21 |
|
| 22 |
|
| 23 |
// Testcase from PR118185 |
| 24 |
|
| 25 |
struct Comp2 |
| 26 |
{ |
| 27 |
constexpr bool operator()(const int&& x, const int&& y) const { return x < y; } |
| 28 |
constexpr bool operator()(const int&& x, int& y) const { return x < y; } |
| 29 |
constexpr bool operator()(int& x, const int&& y) const { return x < y; } |
| 30 |
constexpr bool operator()(int& x, int& y) const { return x < y; } |
| 31 |
constexpr bool operator()(std::same_as<const int&> auto && x, std::same_as<const int&> auto && y) const |
| 32 |
{ |
| 33 |
return x < y; |
| 34 |
} |
| 35 |
}; |
| 36 |
|
| 37 |
static_assert(std::indirect_strict_weak_order<Comp2, std::projected<const int*, Proj>>); |
| 38 |
|
| 39 |
static_assert(std::ranges::clamp(+1, 0, 2, Comp2{}, Proj{}) == 1); |
| 40 |
static_assert(std::ranges::clamp(-1, 0, 2, Comp2{}, Proj{}) == 0); |
| 41 |
static_assert(std::ranges::clamp(10, 0, 2, Comp2{}, Proj{}) == 2); |