Differences between C++98, C++11, C++14, C++17, and C++20?

FeatureC++98C++11C++14C++17C++20
Smart PointersNoYesYesYesYes
Move SemanticsNoYesYesYesYes
Lambda ExpressionsNoYesImprovedYesYes
auto KeywordNoYesYesYesYes
Range-Based For LoopsNoYesYesYesYes
nullptrNoYesYesYesYes
Thread SupportNoYesYesYesYes
ConceptsNoNoNoNoYes
RangesNoNoNoNoYes
CoroutinesNoNoNoNoYes
ModulesNoNoNoNoYes

C++98

Key Features
  • First Standardized Version:
    • Introduced in 1998.
  • Standard Template Library (STL):
    • Provided containers (e.g., std::vector, std::map) and algorithms.
  • Basic Exception Handling:
    • try, catch, and throw keywords for exception handling.
  • Namespaces:
    • Prevented name collisions.
  • Templates:
    • Enabled generic programming.
  • bool Type:
    • Introduced bool type.

C++11

Key Features
  • Smart Pointers:
    • std::unique_ptr, std::shared_ptr for better memory management.
  • Move Semantics:
    • std::move, move constructors, and move assignment operators for efficient resource transfers.
  • Lambda Expressions:
    • Anonymous functions for inline use.
  • auto Keyword:
    • Automatic type deduction.
  • Range-Based for Loops:
    • Simplified iteration over containers.
  • nullptr Keyword:
    • Type-safe null pointer.
  • Thread Support:
    • std::thread, std::mutex, std::lock_guard for multithreading.
Example: Lambda Expression
auto add = [](int a, int b) { return a + b; };

C++14

Key Features
  • Improved Lambda Expressions:
    • Lambda capture by move.
  • Generic Lambdas:
    • Type deduction for parameters.
  • Return Type Deduction:
    • For functions with auto as return type.
  • Variable Templates:
    • Templates for constants.
Example: Generic Lambda
auto add = [](auto a, auto b) { return a + b; };

C++17

Key Features
  • std::optional:
    • Represents optional values.
  • std::variant:
    • Type-safe union.
  • std::any:
    • Holds single value of any type.
  • If-Init Statements:
    • Initialize variables within if and switch.
  • Structured Bindings:
    • Unpack tuples and structs into individual variables.
  • Filesystem Library:
    • std::filesystem for file and directory operations.
Example: Structured Binding
std::tuple<int, int> getCoordinates() { return {1, 2}; }
auto [x, y] = getCoordinates();

C++20

Key Features
  • Concepts:
    • Constraints for template parameters.
  • Ranges:
    • Simplified operations on sequences.
  • Coroutines:
    • Asynchronous programming.
  • Modules:
    • Improved code modularization.
  • Three-Way Comparison (Spaceship Operator):
    • operator<=> for automatic comparisons.
  • Calendar and Time Zone Library:
    • Improved date and time handling.
Example: Concepts
template<typename T>
concept Addable = requires(T a, T b) { a + b; };

template<Addable T>
T add(T a, T b) { return a + b; }