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;
#include <core/exceptions.hpp>
#include <util/path.hpp>
+#include <algorithm>
+
static inline bool
is_blank(const std::string& s)
{
#include <util/path.hpp>
#include <util/string.hpp>
+#include <algorithm>
+
extern "C" {
#include "third_party/base32hex.h"
}
#include <Stat.hpp>
#include <util/Tokenizer.hpp>
-#include <algorithm>
#include <cstdint>
#include <functional>
#include <ios>
// 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.
#include <util/TextTable.hpp>
#include <util/string.hpp>
+#include <algorithm>
+
namespace core {
using core::Statistic;
#include <fcntl.h>
+#include <algorithm>
#include <optional>
#include <string>
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);
-// 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.
//
#include <third_party/doctest.h>
+#include <algorithm>
#include <string>
using TestUtil::TestContext;