2026-08-11 17:40:36 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cctype>
|
|
|
|
|
#include <concepts>
|
2026-08-22 11:33:04 +03:00
|
|
|
#include <sstream>
|
2026-08-11 17:40:36 +03:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace cpp20 {
|
|
|
|
|
|
|
|
|
|
template <std::integral T>
|
|
|
|
|
[[nodiscard]] auto double_value(T value) -> T {
|
2026-08-22 11:33:04 +03:00
|
|
|
return value * 2;
|
2026-08-11 17:40:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <std::floating_point T>
|
|
|
|
|
[[nodiscard]] auto clamp01(T value) -> T {
|
2026-08-22 11:33:04 +03:00
|
|
|
// Converts the 0 and 1 to the right type, which fulfills the std::floating_point concept
|
|
|
|
|
return std::clamp(value, T{0}, T{1});
|
2026-08-11 17:40:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
concept StringLike = requires(T value) {
|
|
|
|
|
{ value.size() } -> std::convertible_to<std::size_t>;
|
|
|
|
|
{ value.data() } -> std::convertible_to<const char*>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <StringLike T>
|
|
|
|
|
[[nodiscard]] auto uppercase_copy(const T& text) -> std::string {
|
2026-08-22 11:33:04 +03:00
|
|
|
auto oss = std::ostringstream{};
|
|
|
|
|
for (auto idx = 0uz; idx < text.size(); idx++) {
|
|
|
|
|
oss << static_cast<char>(std::toupper(text.data()[idx]));
|
|
|
|
|
}
|
|
|
|
|
return oss.str();
|
2026-08-11 17:40:36 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-22 11:33:04 +03:00
|
|
|
template<typename T>
|
|
|
|
|
requires std::integral<T>
|
|
|
|
|
[[nodiscard]] auto sum_integral(const std::vector<T>& data) -> T {
|
|
|
|
|
return std::ranges::fold_left(data, T{0}, std::plus{});
|
|
|
|
|
}
|
2026-08-11 17:40:36 +03:00
|
|
|
|
|
|
|
|
} // namespace cpp20
|