cpp-modern-features
БесплатноБез исполняемых скриптовНе проверенUse when working with modern C++ codebases requiring features from C++11 to C++23 including lambdas, move semantics, ranges, and concepts.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
C++ Modern Features
Master modern C++ features from C++11 through C++23, including lambdas, move semantics, ranges, concepts, and compile-time evaluation. This skill enables you to write efficient, expressive, and maintainable modern C++ code.
C++11 Features
Auto Type Deduction
The auto keyword enables automatic type inference, reducing verbosity and
improving maintainability:
// Traditional
std::vector<int>::iterator it = vec.begin();
std::map<std::string, std::vector<int>>::const_iterator map_it = mymap.find("key");
// Modern C++11
auto it = vec.begin();
auto map_it = mymap.find("key");
// Auto with initialization
auto value = 42; // int
auto pi = 3.14; // double
auto name = std::string("Alice"); // std::string
auto lambda = [](int x) { return x * 2; }; // lambda type
Range-Based For Loops
Simplified iteration over containers and arrays:
std::vector<int> numbers = {1, 2, 3, 4, 5};
// Traditional loop
for (std::vector<int>::iterator it = numbers.begin(); it != numbers.end(); ++it) {
std::cout << *it << " ";
}
// Range-based for (C++11)
for (int num : numbers) {
std::cout << num << " ";
}
// With references to modify elements
for (int& num : numbers) {
num *= 2;
}
// With const references for efficiency
for (const auto& str : string_vector) {
process(str);
}
Lambda Expressions
Anonymous functions with capture capabilities:
// Basic lambda
auto add = [](int a, int b) { return a + b; };
int result = add(3, 4); // 7
// Lambda with captures
int multiplier = 10;
auto multiply = [multiplier](int x) { return x * multiplier; };
// Capture by reference
int counter = 0;
auto increment = [&counter]() { counter++; };
// Capture all by value
auto func1 = [=]() { return x + y + z; };
// Capture all by reference
auto func2 = [&]() { x++; y++; };
// Mixed captures
auto func3 = [&sum, multiplier](int x) { sum += x * multiplier; };
// Mutable lambda (can modify captured values)
auto mutable_func = [counter]() mutable { return counter++; };
Smart Pointers
Automatic memory management with RAII:
#include <memory>
// unique_ptr - exclusive ownership
std::unique_ptr<int> ptr1 = std::make_unique<int>(42);
std::unique_ptr<MyClass> obj = std::make_unique<MyClass>(arg1, arg2);
// shared_ptr - shared ownership with reference counting
std::shared_ptr<int> ptr2 = std::make_shared<int>(100);
std::shared_ptr<int> ptr3 = ptr2; // Reference count = 2
// weak_ptr - non-owning reference
std::weak_ptr<int> weak = ptr2;
if (auto locked = weak.lock()) {
// Use locked pointer safely
std::cout << *locked << std::endl;
}
// Custom deleter
auto deleter = [](FILE* fp) { fclose(fp); };
std::unique_ptr<FILE, decltype(deleter)> file(fopen("data.txt", "r"), deleter);
Nullptr
Type-safe null pointer constant:
// Old way (ambiguous)
void func(int x);
void func(char* ptr);
func(NULL); // Which overload? Depends on NULL definition
// Modern way (unambiguous)
func(nullptr); // Clearly calls func(char*)
// Smart pointer initialization
std::unique_ptr<int> ptr = nullptr;
if (ptr != nullptr) {
// Use ptr
}
C++14 Features
Generic Lambdas
Lambdas with auto parameters:
// Generic lambda (C++14)
auto generic_add = [](auto a, auto b) { return a + b; };
int sum1 = generic_add(3, 4); // Works with int
double sum2 = generic_add(3.14, 2.71); // Works with double
std::string concat = generic_add(std::string("Hello"), std::string(" World"));
// Multiple auto parameters
auto compare = [](auto a, auto b) { return a < b; };
// Use in algorithms
std::vector<int> vec = {5, 2, 8, 1, 9};
std::sort(vec.begin(), vec.end(), [](auto a, auto b) { return a > b; });
Return Type Deduction
Automatic return type for functions:
// C++14: auto return type deduction
auto multiply(int a, int b) {
return a * b; // Return type deduced as int
}
auto get_vector() {
return std::vector<int>{1, 2, 3}; // Deduced as std::vector<int>
}
// Multiple return statements must have same type
auto conditional(bool flag) {
if (flag)
return 42; // int
else
return 100; // int - OK
// return 3.14; // ERROR: different type
}
Make Unique
Factory function for unique_ptr:
// C++11 required manual construction
std::unique_ptr<MyClass> ptr1(new MyClass(arg1, arg2));
// C++14 provides std::make_unique
auto ptr2 = std::make_unique<MyClass>(arg1, arg2);
// Exception safety benefit
func(std::unique_ptr<int>(new int(1)), std::unique_ptr<int>(new int(2))); // Risky
func(std::make_unique<int>(1), std::make_unique<int>(2)); // Safe
C++17 Features
Structured Bindings
Decompose objects into individual variables:
// Pairs and tuples
std::pair<int, std::string> get_data() {
return {42, "Answer"};
}
auto [id, name] = get_data();
std::cout << id << ": " << name << std::endl;
// Maps
std::map<std::string, int> scores = {{"Alic
Установить cpp-modern-features в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
BashReadWriteEditFAQ
Что делает скилл cpp-modern-features?
Use when working with modern C++ codebases requiring features from C++11 to C++23 including lambdas, move semantics, ranges, and concepts.
Как установить скилл cpp-modern-features?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл cpp-modern-features запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic