0% found this document useful (0 votes)
63 views5 pages

Modern CPP 11-20 Sum

The document discusses the new features introduced in C++ 11, C++ 14, and C++ 17 standards. Key features included lambda expressions, auto type deduction, move semantics, multithreading support, and improvements to the standard library in C++ 11. C++ 14 added generic lambdas, return type deduction, variable templates, and constexpr improvements. C++ 17 introduced structured bindings, if/switch initialization, fold expressions, and constexpr if statements.

Uploaded by

Tamás Benyács
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views5 pages

Modern CPP 11-20 Sum

The document discusses the new features introduced in C++ 11, C++ 14, and C++ 17 standards. Key features included lambda expressions, auto type deduction, move semantics, multithreading support, and improvements to the standard library in C++ 11. C++ 14 added generic lambdas, return type deduction, variable templates, and constexpr improvements. C++ 17 introduced structured bindings, if/switch initialization, fold expressions, and constexpr if statements.

Uploaded by

Tamás Benyács
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

--------------------------------------------------------------------------------

--------------------------------------------------------------------------
Which are the new features in the C++ 11 standard?

Lambda Expressions: C++11 introduced lambda expressions, which allow you to


define anonymous functions inline. This feature simplifies code and promotes the
use of functional programming constructs. A concise way to define anonymous
functions (closures) inline, making it easier to write small, one-off functions.

Range-Based for Loops: The range-based for loop simplifies iterating over
sequences, containers, and arrays by automatically managing loop variables and
eliminating the need for manual index manipulation.

Type Inference (auto and decltype): The 'auto' keyword enables type inference,
allowing the compiler to deduce the variable's type from its initializer.
'decltype' lets you determine the type of an expression at compile time.

Smart Pointers: C++11 introduced three smart pointer classes: 'std::shared_ptr',


'std::unique_ptr', and 'std::weak_ptr'. These classes help manage memory more
effectively by automatically releasing resources when they're no longer needed.

Move Semantics and Rvalue References: Introduces move semantics, allowing


efficient transfer of ownership of resources from one object to another, which
improves performance by avoiding unnecessary copying. Rvalue references and the
move constructor support this functionality.

Concurrency and Multithreading Support: C++11 introduced the <thread> header for
multi-threading support, including std::thread, std::mutex,
std::condition_variable, and other synchronization primitives. The 'std::thread'
class was introduced to support concurrent programming. Additionally, the
standard library provides facilities for creating threads, synchronizing
operations, and handling tasks concurrently.

Standard Library Enhancements: C++11 brought numerous additions to the standard


library, including new algorithms, type traits, 'std::function' for handling
function pointers, and more. C++11 added new classes and functions to the
Standard Library, including smart pointers, std::unordered_map,
std::unordered_set, and more. C++11 expanded the standard library with several
new components, including std::array, std::unordered_map, std::unordered_set,
and more, providing better alternatives to some older constructs.

User-Defined Literals: This feature allows developers to define custom literals


(literal suffixes) with custom types and meanings. For instance, you could
define a literal for handling physical units like time or distance. This feature
makes the code more readable for user-defined types.

nullptr: C++11 introduced the 'nullptr' keyword, which is a safer and more
expressive alternative to the traditional use of 'NULL' or '0' for representing
null pointers.

Explicitly Deleted and Defaulted Functions: With C++11, you can explicitly
define functions to be deleted or defaulted, improving code clarity and
preventing unintended behavior.
Override and Final Keywords: Introduced final and override keywords to provide
better control over inheritance and virtual functions. The 'override' keyword
lets you explicitly indicate that a member function is intended to override a
virtual function from a base class. The 'final' keyword prevents further
derivation or overriding.

Scoped Enumerations: Scoped enumerations allow you to limit the scope of


enumeration values, preventing naming conflicts and enhancing code organization.

Uniform Initialization Syntax: C++11 introduced a consistent way to initialize


variables, objects, and arrays using curly braces {}.

Auto Type Deduction: C++11 introduced the auto keyword, allowing you to declare
variables with their type automatically deduced from their initializer. This
simplifies code and promotes type safety.

Auto Type Inference: The auto keyword allows the compiler to automatically infer
the data type of a variable based on its initializer.

Type Traits and static_assert: Introduced type traits, which allow compile-time
introspection of types, and the static_assert keyword for compile-time
assertions. The <type_traits> header introduced a set of type traits that enable
compile-time introspection of types, allowing for more generic and flexible
code.

Atomic Operations: The <atomic> header introduced atomic types and operations
for safe and efficient manipulation of shared variables in a multithreaded
environment.

constexpr: The constexpr keyword indicates that a value or function can be


evaluated at compile-time, promoting performance optimizations.

Standardized Memory Model: C++11 introduced a standardized memory model that


defines the order of operations and interactions between threads.

Initializer Lists: The introduction of initializer lists simplified the process


of initializing arrays, containers, and user-defined types with an easy-to-use
syntax.

--------------------------------------------------------------------------------
--------
Which are the new features in the C++ 14 standard?

Generic Lambdas: C++14 introduced the ability to use lambdas in a more flexible
manner by allowing lambda functions to deduce their parameter types using the
auto keyword. This facilitates the creation of more generic and reusable lambda
functions. C++14 extended lambda functions to support auto-typed parameters in
lambda expressions, making it easier to write generic code.

Return Type Deduction: C++14 introduced the ability to deduce the return type of
a function based on its return statements, using the auto keyword. Functions in
C++14 are allowed to deduce their return types using the auto keyword, enabling
cleaner and more concise code without sacrificing type safety.

Variable Templates: C++14 introduced the concept of variable templates, allowing


template parameters to be used in the declaration of variables. This enhances
code generality and reusability. Similar to function templates, variable
templates allow you to define templates for variables, enabling you to create
flexible and reusable variables.

constexpr Improvements: C++14 expanded the scenarios in which constexpr could be


used, allowing more functions and constructs to be evaluated at compile-time.
The constexpr keyword was made more powerful in C++14, enabling more complex
computations to be performed at compile-time, enhancing the efficiency of code
execution.

Extended constexpr Functions: In C++14, constexpr functions were allowed to


contain a broader set of statements, making it more practical to use them for a
wider range of computations. C++14 extends the scenarios where a function can be
declared as constexpr, enabling more functions to be evaluated at compile-time.

Binary Literals and Digit Separators: C++14 introduced the ability to represent
binary literals (e.g., 0b110101) using the 0b or 0B prefix, making it easier to
work with binary values. Additionally, digit separators (single quotes e.g.,
1'000'000) can now be used within numeric literals to enhance readability.

Extended sizeof Expressions: The sizeof operator in C++14 can now be used with
expressions that have no side effects, offering more flexibility and consistency
in its usage.

Aggregate Member Initialization: C++14 allows for more flexible initialization


of aggregate members (arrays, structs, etc.) using curly braces. This feature
simplifies initialization code and improves code readability.

New Standard Library Features: C++14 introduced several new features to the
standard library, including additions to the <tuple> and <utility> headers,
which enhance the functionality and usability of these library components.

Unicode Character Literals: C++14 enhanced the support for Unicode character
literals, enabling more accurate representation and manipulation of Unicode
characters in the source code.

decltype(auto): This feature lets you deduce the type of a variable using
decltype, similar to how auto is used for type deduction.

std::make_unique: This utility function was introduced to create dynamically


allocated objects with the advantages of std::unique_ptr. It simplifies memory
management and is particularly useful for avoiding memory leaks.

[[deprecated]] Attribute: C++14 introduced the [[deprecated]] attribute that


allows you to mark functions, variables, or types as deprecated, providing
better tooling support for deprecation warnings.

Heterogeneous Lookup for Containers: The C++14 standard extended the container
classes (such as std::unordered_map and std::unordered_set) to support
heterogeneous lookups using types different from the key type.
--------------------------------------------------------------------------------
--------
Which are the new features in the C++ 17 ("C++17 ISO/IEC 14882:2017") standard?

Structured Bindings: C++17 introduced structured bindings, which allow you to


easily decompose structured data, such as tuples and pairs, into individual
variables. This improves code readability and reduces the need for manual
extraction.

if and switch with Initialization: C++17 extended the if and switch statements
to support variable initialization within the statement itself, enhancing code
conciseness and reducing redundancy.

Fold Expressions: Fold expressions provide a compact and expressive way to apply
binary operations over a parameter pack, simplifying code that operates on
variadic template parameters.

constexpr if: C++17 introduced the constexpr if statement, which allows you to
conditionally compile parts of a function template based on compile-time
conditions, improving template specialization.

Inline Variables: C++17 introduced inline variables, enabling you to define


variables in header files without violating the one-definition rule. This can
help improve header-only libraries.

Template Argument Deduction for Class Templates: C++17 extended template


argument deduction to class templates, simplifying the syntax when creating
instances of class templates.

Structured Bindings for std::tuple: In addition to user-defined types, C++17


extended structured bindings to work with std::tuple, making it easier to work
with tuples and improve code readability.

Parallel Algorithms: C++17 introduced parallelism to several algorithms in the


<algorithm> header, allowing you to take advantage of multi-core processors for
enhanced performance.

New Standard Library Features: C++17 introduced several new features in the
standard library, including new algorithms, support for filesystem operations
(<filesystem>), and enhanced support for string handling and manipulation.

New Attributes: C++17 added new attributes, such as [[fallthrough]] for switch
statements and [[nodiscard]] for indicating that a return value should not be
ignored.

std::optional: The std::optional type was introduced as a standard way to


represent optional values, offering a safer alternative to using pointers or
other ad-hoc methods.

constexpr Lambda Functions: C++17 extended constexpr support to lambda


functions, allowing them to be evaluated at compile time when used in constant
expressions.
Other Enhancements: C++17 includes various other improvements, such as
improvements to constexpr functionality, improved support for type deduction in
templates, and standardized attributes for controlling the layout of class
members.

--------------------------------------------------------------------------------
--------
Which are the new features in the C++ 20 standard?

Concepts: C++20 introduces Concepts, which allow you to specify constraints on


template parameters. This helps improve template error messages and provides
more expressive and readable code.

Ranges: The Ranges library simplifies and enhances the manipulation of sequences
of values, making it easier to work with collections of data.

Coroutines: C++20 introduces Coroutines, enabling developers to write


asynchronous code in a more structured and intuitive manner. Coroutines allow
functions to be paused and resumed, simplifying tasks that involve asynchronous
programming.

Modules: The Modules feature aims to improve the organization of code and reduce
compile times by allowing you to define interface units separately from
implementation units.

Three-Way Comparisons: C++20 provides support for three-way comparisons using


the <=> operator, streamlining the process of comparing objects and making
custom types comparable more easily.

Improvements to constexpr: C++20 extends the capabilities of constexpr, allowing


more complex computations to be performed at compile time, leading to potential
performance improvements and more efficient code.

Improved Support for Lambdas: C++20 enhances lambdas by allowing them to appear
in unevaluated contexts and enabling parameter lists to include template and
requires clauses.

Improved std::span: The std::span template provides a non-owning view of a


sequence of elements, helping to avoid unnecessary copying and improve
performance.

Calendar and Time Zone Library: C++20 introduces the <chrono> library with
additional support for working with dates, times, and time zones.

Atomic Smart Pointers: The introduction of atomic smart pointers, such as


std::atomic_shared_ptr and std::atomic_weak_ptr, enables safe concurrent access
to shared resources.

Deprecation and Removals: C++20 deprecates certain features from previous


standards, preparing the way for future improvements. Additionally, some
outdated or rarely used features have been removed.

--------------------------------------------------------------------------------
--------

You might also like