|
Download cpp/cpp-concepts-templates.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/b27bfb3b3b87c2465708a5b87f622c503f21ad4b/cpp/cpp-concepts-templates.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm@b27bfb3b3b87c2465708a5b87f622c503f21ad4b/cpp/cpp-concepts-templates.jsonl
-
curl -L -o cpp-concepts-templates.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/b27bfb3b3b87c2465708a5b87f622c503f21ad4b/cpp/cpp-concepts-templates.jsonl
1.66 kB
| {"type": "session", "harness": "opencode", "id": "cpp-concepts-templates", "name": "Use C++20 concepts for constrained templates and type traits"} | |
| {"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++20 concepts for constrained templates and type traits"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "#include <concepts>\n#include <iostream>\n#include <vector>\n#include <string>\n\ntemplate<typename T>\nconcept Numeric = std::integral<T> || std::floating_point<T>;\n\ntemplate<typename T>\nconcept Container = requires(T t) {\n std::begin(t);\n std::end(t);\n t.size();\n};\n\ntemplate<Numeric T>\nT square(T x) { return x * x; }\n\ntemplate<Container C>\nvoid printContainer(const C& container) {\n for (const auto& item : container) {\n std::cout << item << \" \";\n }\n std::cout << \"\\n\";\n}\n\ntemplate<typename T>\nconcept Printable = requires(std::ostream& os, const T& t) {\n { os << t } -> std::convertible_to<std::ostream&>;\n};\n\ntemplate<Printable T>\nvoid print(const T& value) {\n std::cout << value << \"\\n\";\n}\n\n// Constrained auto\ntemplate<Numeric T>\nauto add(T a, T b) { return a + b; }\n\nint main() {\n std::cout << square(5) << \"\\n\";\n std::cout << square(3.14) << \"\\n\";\n\n std::vector<int> nums = {1, 2, 3, 4, 5};\n std::vector<std::string> words = {\"hello\", \"world\"};\n\n printContainer(nums);\n printContainer(words);\n\n print(42);\n print(\"Hello\");\n\n return 0;\n}"}} | |