From: Joel Rosdahl Date: Sun, 19 Jun 2022 08:09:45 +0000 (+0200) Subject: refactor: Use std::clamp X-Git-Tag: v4.7~178 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ebc876d2df5f0b5122d61668f3adfe052a35a0f;p=thirdparty%2Fccache.git refactor: Use std::clamp --- diff --git a/src/Config.cpp b/src/Config.cpp index 5628e7a81..dae998fc0 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -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(util::parse_double(value)), 0.0, 1.0); break; diff --git a/src/Depfile.cpp b/src/Depfile.cpp index 259006e4d..7ceccc7e7 100644 --- a/src/Depfile.cpp +++ b/src/Depfile.cpp @@ -26,6 +26,8 @@ #include #include +#include + static inline bool is_blank(const std::string& s) { diff --git a/src/Util.cpp b/src/Util.cpp index 19e147999..ebb69bf18 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -32,6 +32,8 @@ #include #include +#include + extern "C" { #include "third_party/base32hex.h" } diff --git a/src/Util.hpp b/src/Util.hpp index 28597d49d..8f06d8c8f 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -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 -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. diff --git a/src/core/Statistics.cpp b/src/core/Statistics.cpp index 0f6c04562..4105d4e36 100644 --- a/src/core/Statistics.cpp +++ b/src/core/Statistics.cpp @@ -25,6 +25,8 @@ #include #include +#include + namespace core { using core::Statistic; diff --git a/src/core/mainoptions.cpp b/src/core/mainoptions.cpp index b7466c844..609fdb55f 100644 --- a/src/core/mainoptions.cpp +++ b/src/core/mainoptions.cpp @@ -44,6 +44,7 @@ #include +#include #include #include diff --git a/unittest/test_Util.cpp b/unittest/test_Util.cpp index 39eafaa09..821c7d2e3 100644 --- a/unittest/test_Util.cpp +++ b/unittest/test_Util.cpp @@ -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); diff --git a/unittest/test_storage_primary_util.cpp b/unittest/test_storage_primary_util.cpp index b847075d9..58d2742e1 100644 --- a/unittest/test_storage_primary_util.cpp +++ b/unittest/test_storage_primary_util.cpp @@ -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 +#include #include using TestUtil::TestContext;