File size: 1,886 Bytes
b27bfb3 | 1 2 3 4 5 | {"type": "session", "harness": "opencode", "id": "cpp98-002", "name": "C++98 templates and STL"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "Explain C++98 templates and STL basics"}}
{"type": "message", "message": {"role": "assistant", "content": "**C++98 Templates and STL:**\n\n**Template Basics:**\n```cpp\ntemplate<typename T>\nT max(T a, T b) {\n return (a > b) ? a : b;\n}\n\nint x = max<int>(3, 5); // explicit\ndouble y = max(3.14, 2.7); // deduced\n```\n\n**Class Templates:**\n```cpp\ntemplate<typename T>\nclass Stack {\n std::vector<T> data;\npublic:\n void push(const T& val) { data.push_back(val); }\n T pop() { T val = data.back(); data.pop_back(); return val; }\n bool empty() const { return data.empty(); }\n};\n\nStack<int> s;\ns.push(42);\n```\n\n**STL Containers:**\n- std::vector: dynamic array\n- std::list: doubly-linked list\n- std::deque: double-ended queue\n- std::map: ordered key-value\n- std::set: ordered unique values\n- std::stack: LIFO adapter\n- std::queue: FIFO adapter\n\n**STL Algorithms:**\n```cpp\nstd::sort(v.begin(), v.end());\nauto it = std::find(v.begin(), v.end(), 5);\nint sum = std::accumulate(v.begin(), v.end(), 0);\nstd::reverse(v.begin(), v.end());\n```\n\n**Iterators:**\n- InputIterator: read, single-pass\n- OutputIterator: write, single-pass\n- ForwardIterator: read/write, multi-pass\n- BidirectionalIterator: + reverse\n- RandomAccessIterator: + arithmetic"}}
|