"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > What are the Key Language and Library Features Introduced in C++17?

What are the Key Language and Library Features Introduced in C++17?

Posted on 2025-02-06
Browse:278

What are the Key Language and Library Features Introduced in C  17?

New Features in C 17

Following the completion of feature development for C 17, several new language features and library additions have been introduced:

Language Features:

  • Improved Template Usage:

    • Template argument deduction for class templates
    • Representation of values of any type with template
  • Lambda Enhancements:

    • Introduction of constexpr lambdas
    • Ability to capture this in lambdas
  • Attributes:

    • Introduction of new attributes, such as [[fallthrough]], [[nodiscard]], and [[maybe_unused]]
  • Syntax Cleanup:

    • Inline variables
    • Simplified namespace syntax: namespace A::B
    • No-throw expressions: throw() and noexcept(true)
  • Control Flow Improvements:

    • Structured bindings for unpacking values
    • if (init; condition) and switch (init; condition) for enhanced flow control
    • Generalized range-based for loops
    • if constexpr for conditional compilation
  • Other Notable Features:

    • Hexadecimal float point literals
    • Dynamic memory allocation for over-aligned data
    • Guaranteed copy elision
    • Fixed order-of-evaluation for expressions
    • Direct list-initialization of enums
    • Forward progress guarantees for threads

Library Additions:

Data Types:

  • std::variant for representing values of different types
  • std::optional for representing optional values
  • std::any for representing values of any type, including non-copyable types
  • std::string_view for efficient handling of string references
  • std::byte for representing data without type information

Callable Handling:

  • std::invoke for generic callable invocation
  • std::apply for tuple-based callable invocation
  • std::make_from_tuple for constructing objects from tuples
  • Introduction of is_invocable and related traits

File System Library:

  • Implementation of the File System Technical Specification (TS)

New Algorithms:

  • for_each_n, reduce, transform_reduce, and more

Threading Enhancements:

  • Introduction of std::shared_mutex for more efficient multi-threaded access
  • Atomic guarantees and hardware interference size detection

Library Fundamentals TS Additions:

  • Searching algorithms (alg.search)
  • Polymorphic allocator (pmr)

Container Improvements:

  • try_emplace and insert_or_assign for efficient container insertion
  • Splicing for maps, sets, and unordered containers
  • Non-const data() access for strings

Smart Pointers:

  • Fixes and tweaks to unique_ptr
  • Introduction of weak_from_this for managing shared pointers

Misc:

  • Use of C11 instead of C99 for the standard library
  • Reserved std[0-9] namespaces for future standard libraries
  • Various utility functions (destroy, uninitialized_***)
  • Exposure of special math functions
  • Introduction of std::clamp, std::gcd, and std::lcm
  • Exception handling improvements, including std::uncaught_exceptions
  • std::as_const, std::bool_constant, and various template utilities
  • Improved std::chrono library
  • Introduction of Boolean operators (std::conjunction, std::disjunction, std::negation)
  • Rules for noexcept usage within std

Deprecated Features:

  • Removal of some C libraries, , result_of, and others
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3