match.pd: Fix indefinite recursion during exp-log transformations [PR118490]
[gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / clamp / 118185.cc
blobe9cf896d35569b7dd56a862e451d3e98f8554e41
1 // { dg-do compile { target c++20 } }
3 #include <algorithm>
4 #include <concepts>
6 struct Comp
8 constexpr bool operator()(const int&& x, const int&& y) { return x < y; }
9 };
11 struct Proj
13 constexpr const int&& operator()(const int& x) const { return std::move(x); }
16 static_assert(std::indirect_strict_weak_order<Comp, std::projected<const int*, Proj>>);
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);
23 // Testcase from PR118185
25 struct Comp2
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
33 return x < y;
37 static_assert(std::indirect_strict_weak_order<Comp2, std::projected<const int*, Proj>>);
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);