From 404095db90e50a8ab9f56936ebccb037aec1bc93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sauren=20Sharma=E2=80=9D?= Date: Sun, 31 Aug 2025 14:45:42 +0530 Subject: [PATCH 1/2] Test --- c++/one.cpp | 94 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 35 deletions(-) diff --git a/c++/one.cpp b/c++/one.cpp index 766e807..999f0df 100644 --- a/c++/one.cpp +++ b/c++/one.cpp @@ -9,43 +9,51 @@ // Advanced template metaprogramming challenge template -class SmartContainer { +class SmartContainer +{ private: std::vector data; - + public: // Intentionally complex insertion with type constraints - template >> - void insert(U value) { + void insert(U value) + { data.push_back(static_cast(value)); } - + // Constrained retrieval method - std::optional get(size_t index) const { - if (index < data.size()) { + std::optional get(size_t index) const + { + if (index < data.size()) + { return data[index]; } return std::nullopt; } - + // Flexible transformation method template >> - void advanced_transform(Func func) { + void advanced_transform(Func func) + { std::transform(data.begin(), data.end(), data.begin(), func); } // Type-safe filtering method template >> - SmartContainer filter(Predicate pred) const { + SmartContainer filter(Predicate pred) const + { SmartContainer result; std::copy_if(data.begin(), data.end(), std::back_inserter(result.data), pred); return result; } // Print method for demonstration - void print() const { - for (const auto& item : data) { + void print() const + { + for (const auto &item : data) + { std::cout << item << " "; } std::cout << std::endl; @@ -53,70 +61,86 @@ class SmartContainer { }; // Base class for a polymorphic type hierarchy -class Shape { +class Shape +{ public: virtual double get_area() const = 0; virtual ~Shape() = default; }; -class Circle : public Shape { +class Circle : public Shape +{ private: double radius; - + public: - explicit Circle(double r) : radius(r) { - if (r <= 0) { + explicit Circle(double r) : radius(r) + { + if (r <= 0) + { throw std::invalid_argument("Radius must be positive"); } } - - double get_area() const override { + + double get_area() const override + { return 3.14159 * radius * radius; } }; -class Rectangle : public Shape { +// Testing commits +class Rectangle : public Shape +{ private: double width; double height; - + public: - Rectangle(double w, double h) : width(w), height(h) { - if (w <= 0 || h <= 0) { + Rectangle(double w, double h) : width(w), height(h) + { + if (w <= 0 || h <= 0) + { throw std::invalid_argument("Dimensions must be positive"); } } - - double get_area() const override { + + double get_area() const override + { return width * height; } }; // Main function demonstrating complex interactions -int main() { +int main() +{ // Template container with type restrictions SmartContainer int_container; int_container.insert(10); int_container.insert(20); int_container.insert(30); - + // Apply a transformation: multiply each element by 2 - int_container.advanced_transform([](int x) { return x * 2; }); + int_container.advanced_transform([](int x) + { return x * 2; }); int_container.print(); // Output: 20 40 60 - + // Filter elements greater than 25 - auto filtered_container = int_container.filter([](int x) { return x > 25; }); + auto filtered_container = int_container.filter([](int x) + { return x > 25; }); filtered_container.print(); // Output: 40 60 - + // Polymorphic shape management std::vector> shapes; - - try { + + try + { shapes.push_back(std::make_unique(5.0)); shapes.push_back(std::make_unique(4.0, 6.0)); - } catch (const std::invalid_argument& e) { + } + catch (const std::invalid_argument &e) + { std::cerr << "Invalid shape: " << e.what() << std::endl; } - + return 0; } \ No newline at end of file From 87536e8e8e9fb3a680654fc6d4ff913d822bdc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sauren=20Sharma=E2=80=9D?= Date: Sun, 31 Aug 2025 14:46:47 +0530 Subject: [PATCH 2/2] Test --- c++/one.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/c++/one.cpp b/c++/one.cpp index 999f0df..d3eaddd 100644 --- a/c++/one.cpp +++ b/c++/one.cpp @@ -7,6 +7,7 @@ #include #include +#define PI 3.14159 // Advanced template metaprogramming challenge template class SmartContainer @@ -84,7 +85,7 @@ class Circle : public Shape double get_area() const override { - return 3.14159 * radius * radius; + return PI * radius * radius; } };