C++17

From Wikipedia, the free encyclopedia
Jump to: navigation, search

C++17 (or, informally, C++1z) is the name for the most recent revision of the ISO/IEC standard for the C++ programming language. The C++17 specification reached the Draft International Standard (DIS) stage in March 2017.[1][2] This DIS was unanimously approved, with only editorial comments,[3] and the final standard was published in December 2017.[4]

New features[edit]

C++17 introduces many new features. The following lists may not be complete.

Language[edit]

  • Making the text message for static_assert optional[5]
  • Allow typename (as an alternative to class) in a template template parameter[8]
  • New rules for auto deduction from braced-init-list[9][10]
  • Nested namespace definitions, e.g., namespace X::Y { … } instead of namespace X { namespace Y { … }}[10][11]
  • Allowing attributes for namespaces and enumerators[12][13]
  • New standard attributes [[fallthrough]], [[maybe_unused]] and [[nodiscard]][14]
  • Hexadecimal floating-point literals[16][17]
  • Constant evaluation for all non-type template arguments[12][18]
  • Fold expressions, for variadic templates[12][19]
  • A compile-time static if with the form if constexpr(expression)[20]
  • Structured binding declarations, allowing auto [a, b] = getTwoReturnValues();[21]
  • Initializers in if and switch statements[22]
  • copy-initialization and direct-initialization of objects of type T from prvalue expressions of type T (ignoring top-level cv-qualifiers) shall result in no copy or move constructors from the prvalue expression.
  • Some extensions on over-aligned memory allocation[23]
  • Template deduction of constructors, allowing std::pair(5.0, false) instead of std::pair<double,bool>(5.0, false)
  • Inline variables, which allows the definition of variables in header files
  • __has_include, allowing the availability of a header to be checked by preprocessor directives[24]
  • Value of __cplusplus changed to 201703L[25]

Library[edit]

  • Most of Library Fundamentals TS I, including:[26][27]
    • std::string_view, a read-only non-owning reference to a character sequence or string-slice[28]
    • std::optional, for representing optional objects
    • std::any, for holding single values of any type
  • std::uncaught_exceptions, as a replacement of std::uncaught_exception[29][12]
  • New insertion functions try_emplace and insert_or_assign for std::map and std::unordered_map [30][31]
  • Uniform container access: std::size, std::empty and std::data[31][32]
  • Definition of "contiguous iterators"[31][33]
  • Removal of some deprecated types and functions, including std::auto_ptr, std::random_shuffle, and old function adaptors[10][34]
  • A file system library based on boost::filesystem[35]
  • Parallel versions of STL algorithms[36]
  • Logical operator traits: std::conjunction, std::disjunction and std::negation[40]

Next standard[edit]

See also[edit]

References[edit]

  1. ^ "N4661 Editors' Report -- Programming Languages -- C++". 21 March 2017. Retrieved 2017-03-21. 
  2. ^ "ISO/IEC DIS 14882: Programming Languages — C++" (PDF). Archived from the original (PDF) on 2017-03-25. 
  3. ^ Herb Sutter. "C++17 is formally approved". 
  4. ^ "ISO/IEC 14882:2017". 
  5. ^ "N3928: Extending static_assert, v2 (Walter E. Brown)" (PDF). 
  6. ^ "N3981: Removing trigraphs??! (Richard Smith)". 2014-05-06. 
  7. ^ IBM comment on preparing for a Trigraph-adverse future in C++17, IBM paper N4210, 2014-10-10. Authors: Michael Wong, Hubert Tong, Rajan Bhakta, Derek Inglis
  8. ^ "N4051: Allow typename in a template template parameter (Richard Smith)". 
  9. ^ "N3922: New Rules for auto deduction from braced-init-list (James Dennett)". 
  10. ^ a b c "Updates to my trip report". 
  11. ^ "N4230: Nested namespace definition (Robert Kawulak, Andrew Tomazos)". 
  12. ^ a b c d e "New core language papers adopted for C++17". 
  13. ^ "N4266: Attributes for namespaces and enumerators (Richard Smith)". 
  14. ^ "N4640: Working Draft, Standard for Programming Language C++" (PDF). pp. 193–195. 
  15. ^ "N4267: Adding u8 character literals (Richard Smith)". 
  16. ^ Thomas Köppe. "Hexadecimal floating literals for C++". 
  17. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §5.13.4. 
  18. ^ "N4268: Allow constant evaluation for all non-type template arguments (Richard Smith)". 
  19. ^ "N4295: Folding expressions (Andrew Sutton, Richard Smith)". 
  20. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §9.4.1. 
  21. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §11.5. 
  22. ^ "If statement with initializer". 
  23. ^ "Dynamic memory allocation for over-aligned data". 
  24. ^ "N4640: Working Draft, Standard for Programming Language C++" (PDF). pp. 431–433. 
  25. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §19.8. 
  26. ^ "Adopt Library Fundamentals V1 TS Components for C++17 (R1)". 
  27. ^ "Current Status". 
  28. ^ "std::basic_string_view - cppreference.com". en.cppreference.com. Retrieved 2016-06-23. 
  29. ^ "N4259: Wording for std::uncaught_exceptions (Herb Sutter)" (PDF). 
  30. ^ "N4279: Improved insertion interface for unique-key maps (Thomas Köppe)". 
  31. ^ a b c "New standard library papers adopted for C++17". 
  32. ^ "N4280: Non-member size() and more (Riccardo Marcangelo)" (PDF). 
  33. ^ "N4284: Contiguous Iterators (Jens Maurer)". 
  34. ^ "N4190: Removing auto_ptr, random_shuffle(), And Old <functional> Stuff (Stephan T. Lavavej)". 
  35. ^ "Filesystem Library Proposal (Beman Dawes)". 
  36. ^ "The Parallelism TS Should be Standardized". 
  37. ^ "Mathematical Special Functions for C++17, v5" (PDF). 
  38. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §23.7. 
  39. ^ "A byte type definition" (PDF). 
  40. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §23.15.8. 
  41. ^ https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"
  42. ^ "Current Status : Standard C++". 
  43. ^ "Trip Report: C++ Standards Meeting in Toronto, July 2017". 2 August 2017. Retrieved 11 January 2018.