[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 24 19:44:40 PDT 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff c60ccfbb898148449946f82cbac6140f1e01cb12 f97313eadac98e753155b5e05ac0eef16f7fb82d -- libcxx/include/__algorithm/ranges_clamp.h libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
index 771169071d77..69d2af0fdf62 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
@@ -34,25 +34,15 @@ struct CreateNoComp {
};
struct Comparator {
- bool operator()(const int&& x, const int&& y) const {
- return x < y;
- }
- bool operator()(const int&& x, int& y) const {
- return x < y;
- }
- bool operator()(int& x, const int&& y) const {
- return x < y;
- }
- bool operator()(int& x, int& y) const {
- return x < y;
- }
- bool operator()(std::same_as<const int&> auto && x, std::same_as<const int&> auto && y) const {
- return x < y;
- }
+ bool operator()(const int&& x, const int&& y) const { return x < y; }
+ bool operator()(const int&& x, int& y) const { return x < y; }
+ bool operator()(int& x, const int&& y) const { return x < y; }
+ bool operator()(int& x, int& y) const { return x < y; }
+ bool operator()(std::same_as<const int&> auto&& x, std::same_as<const int&> auto&& y) const { return x < y; }
};
struct MoveProj {
- const int&& operator()(const int& x) const { return std::move(x); }
+ const int&& operator()(const int& x) const { return std::move(x); }
};
static_assert(std::indirect_strict_weak_order<Comparator, std::projected<const int*, MoveProj>>);
@@ -110,7 +100,7 @@ constexpr bool test() {
}
{ // Make sure we don't call the projection more than three times per [alg.clamp], see #64717
- int counter = 0;
+ int counter = 0;
auto projection_function = [&counter](const int value) -> int {
counter++;
return value;
@@ -124,22 +114,16 @@ constexpr bool test() {
};
// taking by value is important here
- auto comparator = [](std::string a, std::string b) {
- return std::atoi(a.c_str()) < std::atoi(b.c_str());
- };
+ auto comparator = [](std::string a, std::string b) { return std::atoi(a.c_str()) < std::atoi(b.c_str()); };
- auto projection = [](Foo const& foo) {
- return foo.s;
- };
+ auto projection = [](Foo const& foo) { return foo.s; };
Foo foo{"12"};
Foo high{"10"};
Foo low{"1"};
assert(std::ranges::clamp(foo, low, high, comparator, projection).s == "10");
}
- {
- assert(std::ranges::clamp(0, 1, 2, Comparator{}, MoveProj{}) == 1);
- }
+ { assert(std::ranges::clamp(0, 1, 2, Comparator{}, MoveProj{}) == 1); }
return true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/66315
More information about the cfe-commits
mailing list