|
Download cpp/cpp-templates-advanced.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 2.36 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/7fe6853bcbe998c7aec3aa0f7086f584cc091586/cpp/cpp-templates-advanced.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm@7fe6853bcbe998c7aec3aa0f7086f584cc091586/cpp/cpp-templates-advanced.jsonl
-
curl -L -o cpp-templates-advanced.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/7fe6853bcbe998c7aec3aa0f7086f584cc091586/cpp/cpp-templates-advanced.jsonl
2.36 kB
| {"type": "session", "harness": "opencode", "id": "cpp-templates-advanced", "name": "Advanced C++ templates: SFINAE, CRTP, variadic 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": "Advanced C++ templates: SFINAE, CRTP, variadic templates, and type traits"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "#include <iostream>\n#include <type_traits>\n#include <vector>\n#include <string>\n\n// SFINAE\ntemplate<typename T>\nauto print(T x) -> std::enable_if_t<std::is_integral_v<T>> {\n std::cout << \"Integer: \" << x << \"\\n\";\n}\n\ntemplate<typename T>\nauto print(T x) -> std::enable_if_t<std::is_floating_point_v<T>> {\n std::cout << \"Float: \" << x << \"\\n\";\n}\n\n// CRTP\ntemplate<typename Derived>\nclass Counter {\n static int count;\npublic:\n Counter() { ++count; }\n static int getCount() { return count; }\n};\n\ntemplate<typename Derived>\nint Counter<Derived>::count = 0;\n\nclass Widget : public Counter<Widget> {};\nclass Button : public Counter<Button> {};\n\n// Variadic templates\ntemplate<typename... Args>\nvoid printAll(Args... args) {\n ((std::cout << args << \" \"), ...) << \"\\n\";\n}\n\ntemplate<typename T, typename... Args>\nauto makeVector(Args&&... args) {\n std::vector<T> result;\n (result.push_back(T(std::forward<Args>(args))), ...);\n return result;\n}\n\n// Type traits\ntemplate<typename T>\nvoid analyze() {\n std::cout << \"Type: \" << typeid(T).name() << \"\\n\";\n std::cout << \"Size: \" << sizeof(T) << \"\\n\";\n std::cout << \"Trivially copyable: \" << std::is_trivially_copyable_v<T> << \"\\n\";\n std::cout << \"Standard layout: \" << std::is_standard_layout_v<T> << \"\\n\\n\";\n}\n\nint main() {\n print(42);\n print(3.14);\n\n std::cout << \"Widget count: \" << Widget::getCount() << \"\\n\";\n Widget w1, w2;\n std::cout << \"Widget count: \" << Widget::getCount() << \"\\n\";\n\n printAll(1, \"hello\", 3.14, 'c');\n\n auto nums = makeVector<int>(1, 2, 3, 4, 5);\n for (int n : nums) std::cout << n << \" \";\n std::cout << \"\\n\";\n\n analyze<int>();\n analyze<double>();\n analyze<std::string>();\n\n return 0;\n}"}} | |