cpp
यह क्या करती है
यह गाइड आपको ज़्यादा आधुनिक, सुरक्षित और तेज़ C++ कोड लिखने में मदद करती है। यह दिखाती है कि memory, data types, errors को handle करने और एक साथ कई processes पर काम करने (concurrency) के लिए सबसे अच्छे तरीके कैसे इस्तेमाल करें।
कब इस्तेमाल करें
- ✓जब आप modern C++ सीख रहे हों।
- ✓जब आप पहले से लिखे C++ कोड की समीक्षा कर रहे हों।
- ✓जब आपको ऐसा C++ कोड लिखना हो जो तेज़ और सुरक्षित हो।
Skill का लिंक
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/cpp/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं C++ में memory को सुरक्षित तरीके से कैसे manage कर सकता हूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
गाइड 'बुरे' कोड उदाहरणों की तुलना 'अच्छे' C++ उदाहरणों से करती है। यह समझाती है कि modern तरीके आम errors से बचने और performance बढ़ाने में बेहतर क्यों हैं।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
C++: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for cpp.
Table of Contents
- Memory & Ownership
- Modern Types & Containers
- Move Semantics & References
- Templates & Concepts
- Error Handling
- Concurrency
- Anti-patterns specific to C++
1. Memory & Ownership {#memory}
// ❌ Raw new/delete
Widget* w = new Widget();
// ... 15 lines later ...
delete w;
// ✅
auto w = std::make_unique<Widget>();
// ❌ Shared ownership when unique suffices
auto w = std::make_shared<Widget>();
transfer(w); // only one owner
// ✅ — unique_ptr; move when transferring
auto w = std::make_unique<Widget>();
transfer(std::move(w));
// ❌ new[] for dynamic arrays
int* arr = new int[n];
// ... use ...
delete[] arr;
// ✅
std::vector<int> arr(n);
// ❌ Manual RAII wrapper for file/mutex
FILE* f = fopen(path, "r");
// ... must remember fclose ...
// ✅
std::ifstream f(path);
// closes automatically at scope exit
// For non-standard resources: use unique_ptr with custom deleter
auto f = std::unique_ptr<FILE, decltype(&fclose)>(fopen(path, "r"), fclose);
Rule: if you type new, you almost certainly want make_unique or make_shared.
2. Modern Types & Containers {#types}
// ❌ C-style string manipulation
char buf[256];
sprintf(buf, "%s:%d", host, port);
// ✅
auto addr = std::format("{}:{}", host, port); // C++20
// or: auto addr = host + ":" + std::to_string(port);
// ❌ out-parameter for multiple returns
void compute(int input, int& result, std::string& error);
// ✅
struct ComputeResult { int value; std::string error; };
ComputeResult compute(int input);
// or: std::pair / std::tuple with structured bindings
auto [value, error] = compute(input);
// ❌ Manual loop to find element
int idx = -1;
for (int i = 0; i < vec.size(); i++) {
if (vec[i] == target) { idx = i; break; }
}
// ✅
auto it = std::ranges::find(vec, target); // C++20
// or: std::find(vec.begin(), vec.end(), target);
// ❌ Checking .find() != .end() then accessing
auto it = map.find(key);
if (it != map.end()) { use(it->second); }
// ✅ (C++20)
if (map.contains(key)) { use(map[key]); }
// or keep iterator version when you need the value without double lookup
Use std::string_view for function parameters that don't need ownership.
3. Move Semantics & References {#move}
// ❌ Copying a large container into a function
void process(std::vector<Data> items) { ... } // copies on call
// ✅ — const ref for read, move for sink
void process(const std::vector<Data>& items) { ... } // read-only
void consume(std::vector<Data> items) { ... } // sink: caller moves in
// ❌ std::move on const object (silently copies)
const std::string s = "hello";
take(std::move(s)); // still copies
// ✅ — don't const things you intend to move
std::string s = "hello";
take(std::move(s));
// ❌ Returning std::move from local (prevents NRVO)
std::vector<int> build() {
std::vector<int> v;
// ... fill ...
return std::move(v); // pessimization
// ✅ — just return the local; compiler applies NRVO or implicit move
return v;
}
4. Templates & Concepts {#templates}
// ❌ SFINAE soup
template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
T square(T x) { return x * x; }
// ✅ (C++20 concepts)
template<std::integral T>
T square(T x) { return x * x; }
// ❌ Template for one type
template<typename T>
void log(T msg) { std::cout << msg; }
// Only ever called with std::string
// ✅ — don't templatize unless you need multiple types
void log(std::string_view msg) { std::cout << msg; }
Concepts make template errors readable — prefer them over SFINAE and static_assert.
5. Error Handling {#errors}
// ❌ Error codes via int returns (C-style in C++)
int parse(const std::string& input, Data& out);
// ✅ — std::expected (C++23) or exceptions
std::expected<Data, ParseError> parse(const std::string& input);
// or throw for exceptional conditions
Data parse(const std::string& input); // throws ParseError
// ❌ Catching by value (slices derived exceptions)
try { ... }
catch (std::exception e) { ... }
// ✅
catch (const std::exception& e) { ... }
…
अक्सर पूछे जाने वाले सवाल
'RAII' क्या है?
RAII का मतलब है 'Resource Acquisition Is Initialization'। यह C++ की एक तकनीक है, जिसमें object बनने या खत्म होने पर resources (जैसे memory या files) अपने आप manage हो जाते हैं। उदाहरण के लिए, जब किसी file को दर्शाने वाला object scope से बाहर जाता है, तो file अपने आप बंद हो जाती है।
`new int[n]` की जगह `std::vector` क्यों इस्तेमाल करें?
`std::vector` memory को अपने आप manage करता है, जिससे आपको memory को हाथ से allocate और deallocate करने की चिंता नहीं करनी पड़ती, जो errors का कारण बन सकता है। इसमें काम की और भी कई सुविधाएँ होती हैं।
'move semantics' क्या हैं?
Move semantics एक तरीका है जिससे बड़े data blocks जैसे resources को objects के बीच ज़्यादा तेज़ी से transfer किया जा सके। सब कुछ copy करने के बजाय, यह resources की ownership 'move' कर देता है, जिससे काम काफी तेज़ हो जाता है।
जानकारी
लेखक का मूल विवरण
Language-specific super-code guidelines for cpp.
लोकप्रियता
- GitHub स्टार
- 48k
- रैंकिंग में स्थान
- #5888
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
00-andruia-consultant
48kआपके एजेंट को AI प्रोजेक्ट शुरू करने या उन्हें बेहतर बनाने में मदद करता है। यह code का विश्लेषण करता है, tools सुझाता है और स्पेनिश भाषा में action plan बनाता है।
007
48kआपका एजेंट security audit और threat modeling करता है। यह प्रोजेक्ट को हमलों और कमजोरियों से बचाने में काम आता है।
10-andruia-skill-smith
48kआपके एजेंट को AI tools बनाने या उन्हें बेहतर करने में मदद करता है। यह तय करता है कि tools कैसे काम करेंगे, documentation लिखता है और structure की जांच करता है।
20-andruia-niche-intelligence
48kआपका एजेंट किसी खास industry का summary बनाता है। भरोसेमंद स्रोतों की मदद से यह प्रोजेक्ट का संदर्भ, नियम, इस्तेमाल के तरीके और जोखिम समझने में मदद करता है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।