api: "YAML JSON TOON Database" version: 1.0.0 format: json dataset: id: 49 slug: cpp-modern-features title: "Modern C++ Features (C++11 through C++23)" description: "Modern C++ features from C++11 to C++23: smart pointers, move semantics, lambdas, concepts, ranges, coroutines, and modules." category: "Programming Languages" category_slug: programming-languages tags: "cpp,c++,modern-cpp,smart-pointers,lambdas,concepts,ranges,coroutines" view_count: 0 created_at: 1778695229 updated_at: 1778695229 data: features [12]{name,standard,description,example}: "Smart Pointers",C++11,"Automatic memory management: unique_ptr (exclusive ownership), shared_ptr (reference counting), weak_ptr (non-owning observer)","auto ptr = std::make_unique();" "Move Semantics",C++11,"Transfer resources instead of copying: rvalue references (&&), std::move, move constructors/assignment operators","std::vector v2 = std::move(v1);" "Lambda Expressions",C++11,"Anonymous functions with capture lists, mutable lambdas, generic lambdas (auto params in C++14)","auto add = [capture](int x) { return x + offset; };" "auto Type Deduction",C++11,"Compiler deduces type from initializer expression, reduces verbosity","auto it = map.find(key); auto [key, val] = *it;" constexpr,C++11/14/17,"Compile-time evaluation: C++11 (limited), C++14 (loops/branches), C++17 (if constexpr)","constexpr int factorial(int n) { return n <= 1 ? 1 : n * factorial(n-1); }" "Range-based for",C++11,"Simplified iteration over containers and initializer lists","for (const auto& item : container) { /* ... */ }" "Structured Bindings",C++17,"Decompose tuples, pairs, and structs into named variables","auto [name, age] = getPerson();" "std::optional",C++17,"Type-safe alternative to nullable pointers, represents optional values","std::optional findUser(int id);" Concepts,C++20,"Named compile-time constraints on template parameters, better error messages","template T add(T a, T b) { return a + b; }" Ranges,C++20,"Composable algorithms operating on ranges: views (lazy), actions (eager), pipe operator","auto evens = numbers | std::views::filter([](int n){ return n%2==0; }) | std::views::take(10);" Coroutines,C++20,"Functions that can suspend and resume: co_await, co_yield, co_return","Generator fib() { co_yield 0; co_yield 1; /* ... */ }" Modules,C++20,"Replace #include with import/export for faster compilation and better encapsulation","import std; export module mylib;"