Home > Backend Development > C++ > What are the Key Language and Library Features Introduced in C 17?

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

Linda Hamilton
Release: 2024-12-13 16:33:13
Original
214 people have browsed it

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

The above is the detailed content of What are the Key Language and Library Features Introduced in C 17?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template