C++ 11 features with complete examples
This page summarises the features introduced in C++11, grouped by learning complexity, frequency of use, and conceptual depth. The goal is to guide developers through a structured learning path.
C++ 11 for Beginners
autotype deduction – Simplifies variable declarations – Explanation with an Examplenullptr– Safer alternative toNULL– Explanation with an Exampleenum class– Scoped and strongly-typed enumerations – Explanation with an Examplestatic_assert– Compile-time assertions to catch errors early – Explanation with an Example- Range-based
forloops – Simplifies iteration over STL containers – Explanation with an Example finalandoverride– Improves clarity and correctness in inheritance – Explanation with an Example- Uniform initialization &
initializer_list– Consistent initialization syntax – Explanation with an Example - Explicit
default/delete– Control over special member functions – Explanation with an Example
C++ 11 for Intermediate
- Lambda expressions – Anonymous functions; essential for STL algorithms.
constexpr– Enables compile-time computations.- Defaulted/deleted functions – Explicit control of constructors and assignment operators.
- Delegating constructors – Constructor reuse within a class.
- Inheriting constructors – Automatically inherits base constructors.
- Trailing return types – Return types after the parameter list using
->. decltype– Deduces the type of an expression.noexcept– Indicates whether a function throws.- Forward-declared scoped enums – Useful for large header-based designs.
- STL additions:
std::array,std::unordered_map, etc.
C++ 11 for Advanced
- Rvalue references & move semantics – Enables efficient resource transfer.
- Variadic templates – Functions/classes that accept a variable number of template arguments.
- User-defined literals – Custom suffixes for literals (e.g.,
42_km). std::moveandstd::forward– Helpers for move semantics and perfect forwarding.- Smart pointers –
std::unique_ptr,std::shared_ptr,std::weak_ptr. std::tuple,std::bind,std::function– For generic and functional-style code.- Thread support:
std::thread,std::mutex,std::lock_guard, etc. std::chrono– Time utilities and duration handling.std::regex– Regular expressions support.- Futures and async:
std::future,std::async,std::promise. <type_traits>– Template metaprogramming utilities.std::begin,std::end– Range-based iteration support.