|
Download cpp/cpp-move-semantics.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 2.2 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/main/cpp/cpp-move-semantics.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm/cpp/cpp-move-semantics.jsonl
-
curl -L -o cpp-move-semantics.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/main/cpp/cpp-move-semantics.jsonl
2.2 kB
| {"type": "session", "harness": "opencode", "id": "cpp-move-semantics", "name": "Use C++ move semantics, perfect forwarding, and RVO/NRVO optimization"} | |
| {"type": "message", "message": {"role": "system", "content": "You are an expert C++ developer. You write clean, efficient, and idiomatic code."}} | |
| {"type": "message", "message": {"role": "user", "content": "Use C++ move semantics, perfect forwarding, and RVO/NRVO optimization"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "#include <iostream>\n#include <vector>\n#include <string>\n#include <memory>\n\nclass Buffer {\n size_t size_;\n int* data_;\npublic:\n explicit Buffer(size_t size) : size_(size), data_(new int[size]) {\n std::cout << \"Constructed (\" << size_ << \")\\n\";\n }\n\n // Move constructor\n Buffer(Buffer&& other) noexcept : size_(other.size_), data_(other.data_) {\n other.size_ = 0;\n other.data_ = nullptr;\n std::cout << \"Moved\\n\";\n }\n\n // Move assignment\n Buffer& operator=(Buffer&& other) noexcept {\n if (this != &other) {\n delete[] data_;\n size_ = other.size_;\n data_ = other.data_;\n other.size_ = 0;\n other.data_ = nullptr;\n std::cout << \"Move assigned\\n\";\n }\n return *this;\n }\n\n // Deleted copy operations\n Buffer(const Buffer&) = delete;\n Buffer& operator=(const Buffer&) = delete;\n\n ~Buffer() { delete[] data_; }\n\n size_t size() const { return size_; }\n};\n\n// Perfect forwarding\ntemplate<typename T, typename... Args>\nstd::unique_ptr<T> make(Args&&... args) {\n return std::make_unique<T>(std::forward<Args>(args)...);\n}\n\n// Factory with RVO\nBuffer createBuffer(size_t size) {\n return Buffer(size); // RVO or NRVO\n}\n\nint main() {\n // Named RVO\n Buffer b1 = createBuffer(1024);\n\n // Move\n Buffer b2 = std::move(b1);\n\n // Move assignment\n b1 = createBuffer(2048);\n\n // Vector with move\n std::vector<Buffer> vec;\n vec.push_back(createBuffer(512)); // Move into vector\n\n // emplace_back\n vec.emplace_back(1024);\n\n return 0;\n}"}} | |