UNPKG

codebridge-ai

Version:

Complete fullstack AI coding platform with AST-based code integration and local LLM support. Now with comprehensive web technology support (HTML/CSS/JS) plus JavaScript, Python, Rust, and C++.

21 lines 1.62 kB
{ "timestamp": "2025-08-02T16:16:12.839Z", "model": "deepseek-coder:6.7b", "language": "cpp", "scenario": "modern-cpp", "task": "Convert to use smart pointers and modern C++ features", "originalCode": "int* createArray(int size) {\n int* arr = new int[size];\n for(int i = 0; i < size; i++) {\n arr[i] = i;\n }\n return arr;\n}", "rawResponse": "You can replace raw pointer with `std::unique_ptr<int[]>` which automatically deallocates memory when it's no longer in use. Here is how you could rewrite your function to make use of smart pointers and modern C++ features:\n\n```cpp\n#include <memory>\n\nstd::unique_ptr<int[]> createArray(int size) {\n std::unique_ptr<int[]> arr = std::make<|begin▁of▁sentence|>int[size]();\n for(int i = 0; i < size; i++) {\n arr[i] = i;\n }\n return arr;\n}\n```\n\nPlease note that the `std::unique_ptr` is a move-only type and thus can't be copied. If you need to pass it around or store it, consider using `std::shared_ptr<int[]>` instead which allows copying but still ensures proper deallocation when no longer in use.\n", "improvedCode": "#include <memory>\n\nstd::unique_ptr<int[]> createArray(int size) {\n std::unique_ptr<int[]> arr = std::make<|begin▁of▁sentence|>int[size]();\n for(int i = 0; i < size; i++) {\n arr[i] = i;\n }\n return arr;\n}", "duration": 5182, "success": true, "qualityMetrics": { "hasCode": true, "hasSmartPointers": true, "hasStdLibrary": true, "score": 0.6153846153846154, "rawScore": 0.8, "maxScore": 1.3 }, "error": null }