|
Download cpp/cpp-stl-algorithms.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/034ba678829a1c436b19d43dd3adab33b5170a80/cpp/cpp-stl-algorithms.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm@034ba678829a1c436b19d43dd3adab33b5170a80/cpp/cpp-stl-algorithms.jsonl
-
curl -L -o cpp-stl-algorithms.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/034ba678829a1c436b19d43dd3adab33b5170a80/cpp/cpp-stl-algorithms.jsonl
2.1 kB
| {"type": "session", "harness": "opencode", "id": "cpp-stl-algorithms", "name": "Master C++ STL algorithms: sort, transform, accumulate, and parallel execution"} | |
| {"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": "Master C++ STL algorithms: sort, transform, accumulate, and parallel execution"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "#include <algorithm>\n#include <numeric>\n#include <vector>\n#include <execution>\n#include <ranges>\n#include <iostream>\n#include <random>\n\nint main() {\n std::vector<int> nums = {5, 3, 1, 4, 2, 8, 7, 6};\n\n // Sort\n std::sort(nums.begin(), nums.end());\n std::sort(nums.begin(), nums.end(), std::greater<int>());\n\n // Binary search (requires sorted)\n std::sort(nums.begin(), nums.end());\n bool found = std::binary_search(nums.begin(), nums.end(), 5);\n\n // Transform\n std::vector<int> doubled(nums.size());\n std::transform(nums.begin(), nums.end(), doubled.begin(), [](int x) { return x * 2; });\n\n // Accumulate\n int sum = std::accumulate(nums.begin(), nums.end(), 0);\n int product = std::accumulate(nums.begin(), nums.end(), 1, std::multiplies<int>());\n\n // Remove-erase idiom\n nums.erase(std::remove_if(nums.begin(), nums.end(), [](int x) { return x % 2 == 0; }), nums.end());\n\n // Partial sort\n std::partial_sort(nums.begin(), nums.begin() + 3, nums.end());\n\n // nth_element\n std::nth_element(nums.begin(), nums.begin() + nums.size()/2, nums.end());\n\n // Parallel algorithms (C++17)\n std::vector<int> large(1000000);\n std::iota(large.begin(), large.end(), 0);\n std::sort(std::execution::par, large.begin(), large.end());\n\n // C++20 ranges\n auto evens = large | std::views::filter([](int x) { return x % 2 == 0; })\n | std::views::take(10);\n\n for (auto v : evens) std::cout << v << \" \";\n std::cout << \"\\n\";\n\n return 0;\n}"}} | |