tinycodinglm / cpp /cppstd001.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
1.94 kB
deepseek-harness trace
System 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 c...

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.

User

What are the key C++ standard library features?

Assistant
cpp
// Containers
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <array>
#include <deque>
#include <list>

std::vector<int> v = {1, 2, 3};
v.push_back(4);
v.emplace_back(5);
auto& ref = v[0];

std::map<std::string, int> m = {{"a", 1}};
m["b"] = 2;
auto it = m.find("a");

std::unordered_map<std::string, int> um;  // O(1) lookup

// Algorithms
#include <algorithm>
#include <numeric>

std::sort(v.begin(), v.end());
std::sort(v.begin(), v.end(), std::greater<int>());
auto it = std::find(v.begin(), v.end(), 3);
int sum = std::accumulate(v.begin(), v.end(), 0);
std::reverse(v.begin(), v.end());
auto [min_it, max_it] = std::minmax_element(v.begin(), v.end());

// Smart pointers
#include <memory>
auto up = std::make_unique<int>(42);
auto sp = std::make_shared<int>(42);
std::weak_ptr<int> wp = sp;

// String
#include <string>
std::string s = "hello";
s.substr(0, 3);
s.find("ell");
auto parts = s | std::views::split(' ');

// Optional/Variant/Any (C++17)
#include <optional>
#include <variant>
#include <any>
std::optional<int> opt = 42;
std::variant<int, std::string> var = "hello";
std::any a = 42;