Solved: 43 - Concepts

This commit is contained in:
2026-08-22 11:33:04 +03:00
parent 8fa5630858
commit 57693c5de2
3 changed files with 15 additions and 12 deletions
+14 -7
View File
@@ -3,6 +3,7 @@
#include <algorithm>
#include <cctype>
#include <concepts>
#include <sstream>
#include <string>
#include <vector>
@@ -10,14 +11,13 @@ namespace cpp20 {
template <std::integral T>
[[nodiscard]] auto double_value(T value) -> T {
(void)value;
return T{};
return value * 2;
}
template <std::floating_point T>
[[nodiscard]] auto clamp01(T value) -> T {
(void)value;
return T{};
// Converts the 0 and 1 to the right type, which fulfills the std::floating_point concept
return std::clamp(value, T{0}, T{1});
}
template <typename T>
@@ -28,10 +28,17 @@ concept StringLike = requires(T value) {
template <StringLike T>
[[nodiscard]] auto uppercase_copy(const T& text) -> std::string {
(void)text;
return {};
auto oss = std::ostringstream{};
for (auto idx = 0uz; idx < text.size(); idx++) {
oss << static_cast<char>(std::toupper(text.data()[idx]));
}
return oss.str();
}
[[nodiscard]] auto sum_integral(const std::vector<int>& data) -> int;
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{});
}
} // namespace cpp20