]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Use std::clamp
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 19 Jun 2022 08:09:45 +0000 (10:09 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 19 Jun 2022 19:29:00 +0000 (21:29 +0200)
src/Config.cpp
src/Depfile.cpp
src/Util.cpp
src/Util.hpp
src/core/Statistics.cpp
src/core/mainoptions.cpp
unittest/test_Util.cpp
unittest/test_storage_primary_util.cpp

index 5628e7a81bd9a2ad6af7c2db030eca5f35731328..dae998fc0c3bece67221c6c8a6e42e7502d14bc4 100644 (file)
@@ -925,7 +925,7 @@ Config::set_item(const std::string& key,
     break;
 
   case ConfigItem::limit_multiple:
-    m_limit_multiple = Util::clamp(
+    m_limit_multiple = std::clamp(
       util::value_or_throw<core::Error>(util::parse_double(value)), 0.0, 1.0);
     break;
 
index 259006e4da59365108df83e51085974d0ad14de0..7ceccc7e77dcaa5ca4ce3c3a171b01a190f0fde4 100644 (file)
@@ -26,6 +26,8 @@
 #include <core/exceptions.hpp>
 #include <util/path.hpp>
 
+#include <algorithm>
+
 static inline bool
 is_blank(const std::string& s)
 {
index 19e147999342dd6814fc240dc221414ec18b58e4..ebb69bf1830c00a76c719f516dc6998406c16828 100644 (file)
@@ -32,6 +32,8 @@
 #include <util/path.hpp>
 #include <util/string.hpp>
 
+#include <algorithm>
+
 extern "C" {
 #include "third_party/base32hex.h"
 }
index 28597d49d45bf303fd1a54417f51175c212141fa..8f06d8c8f2992b90b3ed535995da1128ecc8a0d9 100644 (file)
@@ -21,7 +21,6 @@
 #include <Stat.hpp>
 #include <util/Tokenizer.hpp>
 
-#include <algorithm>
 #include <cstdint>
 #include <functional>
 #include <ios>
@@ -79,14 +78,6 @@ big_endian_to_int(const uint8_t* buffer, uint8_t& value)
 // should start with a dot, no extra dot is inserted.
 std::string change_extension(std::string_view path, std::string_view new_ext);
 
-// Return `value` adjusted to not be less than `min` and not more than `max`.
-template<typename T>
-T
-clamp(T value, T min, T max)
-{
-  return std::min(max, std::max(min, value));
-}
-
 // Clone a file from `src` to `dest`. If `via_tmp_file` is true, `src` is cloned
 // to a temporary file and then renamed to `dest`. Throws `core::Error` on
 // error.
index 0f6c045621d7bc68c6482ade683ca0ef25badf16..4105d4e3684066edfa3e06a5337230f73c30cd41 100644 (file)
@@ -25,6 +25,8 @@
 #include <util/TextTable.hpp>
 #include <util/string.hpp>
 
+#include <algorithm>
+
 namespace core {
 
 using core::Statistic;
index b7466c8444a9a4a997e936daa45caf93cb6f0f04..609fdb55f35547c1919bdcc2ae51d7a984808759 100644 (file)
@@ -44,6 +44,7 @@
 
 #include <fcntl.h>
 
+#include <algorithm>
 #include <optional>
 #include <string>
 
index 39eafaa0905063977e251f60ce60d146102bef7c..821c7d2e363d368ca828df6e362ca5cd3ca63af8 100644 (file)
@@ -104,18 +104,6 @@ TEST_CASE("Util::change_extension")
   CHECK(Util::change_extension("foo.bar.txt", ".o") == "foo.bar.o");
 }
 
-TEST_CASE("Util::clamp")
-{
-  CHECK(Util::clamp(0, 1, 2) == 1);
-  CHECK(Util::clamp(1, 1, 2) == 1);
-  CHECK(Util::clamp(2, 1, 2) == 2);
-  CHECK(Util::clamp(3, 1, 2) == 2);
-
-  CHECK(Util::clamp(7.0, 7.7, 8.8) == Approx(7.7));
-  CHECK(Util::clamp(8.0, 7.7, 8.8) == Approx(8.0));
-  CHECK(Util::clamp(9.0, 7.7, 8.8) == Approx(8.8));
-}
-
 TEST_CASE("Util::common_dir_prefix_length")
 {
   CHECK(Util::common_dir_prefix_length("", "") == 0);
index b847075d96e247f803eeac99e7cb082cb5b7fb0b..58d2742e1fc39337c63b8b0a7d0421e0d471c95e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2021 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -23,6 +23,7 @@
 
 #include <third_party/doctest.h>
 
+#include <algorithm>
 #include <string>
 
 using TestUtil::TestContext;