diff --git a/modules/12_cpp20/include/concepts.hpp b/modules/12_cpp20/include/concepts.hpp index 0e834ee..b8b651c 100644 --- a/modules/12_cpp20/include/concepts.hpp +++ b/modules/12_cpp20/include/concepts.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -10,14 +11,13 @@ namespace cpp20 { template [[nodiscard]] auto double_value(T value) -> T { - (void)value; - return T{}; + return value * 2; } template [[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 @@ -28,10 +28,17 @@ concept StringLike = requires(T value) { template [[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(std::toupper(text.data()[idx])); + } + return oss.str(); } -[[nodiscard]] auto sum_integral(const std::vector& data) -> int; +template +requires std::integral +[[nodiscard]] auto sum_integral(const std::vector& data) -> T { + return std::ranges::fold_left(data, T{0}, std::plus{}); +} } // namespace cpp20 diff --git a/modules/12_cpp20/src/concepts.cpp b/modules/12_cpp20/src/concepts.cpp index 6fd74f0..56ff472 100644 --- a/modules/12_cpp20/src/concepts.cpp +++ b/modules/12_cpp20/src/concepts.cpp @@ -2,9 +2,5 @@ namespace cpp20 { -auto sum_integral(const std::vector& data) -> int { - (void)data; - return 0; -} } // namespace cpp20 diff --git a/modules/12_cpp20/test/concepts_test.cpp b/modules/12_cpp20/test/concepts_test.cpp index 50d56ea..1e65522 100644 --- a/modules/12_cpp20/test/concepts_test.cpp +++ b/modules/12_cpp20/test/concepts_test.cpp @@ -15,5 +15,5 @@ TEST(Concepts, UppercaseCopy) { } TEST(Concepts, SumIntegral) { - EXPECT_EQ(cpp20::sum_integral({1, 2, 3}), 6); + EXPECT_EQ(cpp20::sum_integral({1, 2, 3}), 6); }