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.65 kB
{ "timestamp": "2025-08-02T14:34:39.063Z", "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 utilize `std::unique_ptr` for automatic memory management in modern C++. Here is how you could rewrite your function using this feature:\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|>(size);\n for (int i = 0; i < size; ++i) {\n arr[i] = i;\n }\n return arr;\n}\n```\nIn this code, `std::unique_ptr<int[]>` is a smart pointer that manages an array of integers. The function returns a unique pointer to the dynamically allocated integer array. This way, memory will be automatically deallocated when it's no longer in use. \n\nRemember to include `#include <memory>` at the beginning of your file to use `std::unique_ptr` and other smart pointers.\n", "improvedCode": "#include <memory>\n\nstd::unique_ptr<int[]> createArray(int size) {\n std::unique_ptr<int[]> arr = std::make<|begin▁of▁sentence|>(size);\n for (int i = 0; i < size; ++i) {\n arr[i] = i;\n }\n return arr;\n}", "duration": 5185, "success": true, "qualityMetrics": { "hasCode": true, "hasSmartPointers": true, "hasStdLibrary": true, "score": 0.6153846153846154, "rawScore": 0.8, "maxScore": 1.3 }, "error": null }