请输入您要查询的百科知识:

 

词条 C++17
释义

  1. History

     Next standard 

  2. Removed

  3. New features

     Language  Library 

  4. Compiler support

  5. See also

  6. References

{{distinguish|C17 (C standard revision)}}{{As of|2018}}, C++17 is the name for the most recent revision of the ISO/IEC 14882 standard for the C++ programming language.

History

Before the C++ Standards Committee fixed a 3-year release cycle, C++17's release date was uncertain. In that time period, the C++17 revision was also called C++1z, following C++0x or C++1x for C++11 and C++1y for C++14. 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] Few changes were made to the C++ Standard Template Library, although some algorithms in the header were given support for explicit parallelization and some syntactic enhancements were made.

Next standard

  • C++20[5][6][7]

Removed

This revision of C++ not only added new features but also removed a few.

  • Removal of trigraphs[8][9]
  • Removal of some deprecated types and functions from the standard library, including std::auto_ptr, std::random_shuffle, and old function adaptors[10][10]

New features

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

Language

  • Making the text message for {{code|2=cpp|1=static_assert}} optional[11]
  • Allow {{code|2=cpp|1=typename}} (as an alternative to {{code|2=cpp|1=class}}) in a template template parameter[12]
  • New rules for {{code|2=cpp|1=auto}} deduction from braced-init-list[13][14]
  • Nested namespace definitions, e.g., {{code|2=cpp|1=namespace X::Y { … } }} instead of {{code|2=cpp|1=namespace X { namespace Y { … } } }}[14][15]
  • Allowing attributes for namespaces and enumerators[18][16]
  • New standard attributes {{code|2=cpp|1=fallthrough}}, {{code|2=cpp|1=maybe_unused}} and {{code|2=cpp|1=nodiscard}}[17]
  • UTF-8 ({{code|2=cpp|1=u8}}) character literals[18][18] (UTF-8 string literals have existed since C++11; C++17 adds the corresponding character literals for consistency, though as they are restricted to a single byte they can only store ASCII)
  • Hexadecimal floating-point literals[19][20]
  • Constant evaluation for all non-type template arguments[18][21]
  • Fold expressions, for variadic templates[18][22]
  • A compile-time static {{code|2=cpp|1=if}} with the form {{code|2=cpp|1=if constexpr(expression)}}[23]
  • Structured binding declarations, allowing {{code|2=cpp|1=auto [a, b] = getTwoReturnValues();}}[24]
  • Initializers in {{code|2=cpp|1=if}} and {{code|2=cpp|1=switch}} statements[25]
  • copy-initialization and direct-initialization of objects of type {{code|2=cpp|1=T}} from prvalue expressions of type {{code|2=cpp|1=T}} (ignoring top-level cv-qualifiers) shall result in no copy or move constructors from the prvalue expression. See copy elision for more information.
  • Some extensions on over-aligned memory allocation[26]
  • Class template argument deduction (CTAD), introducing constructor deduction guides, eg. allowing {{code|2=cpp|1=std::pair(5.0, false)}} instead of explicitly specifying constructor arguments types {{code|2=cpp|1=std::pair(5.0, false)}} or without an additional helper template function {{code|2=cpp|1=std::make_pair(5.0, false)}}.[27][28]
  • Inline variables, which allows the definition of variables in header files without violating the one definition rule. The rules are effectively the same as inline functions
  • {{code|2=cpp|1=__has_include}}, allowing the availability of a header to be checked by preprocessor directives[29]
  • The keyword {{code|2=cpp|1=register}} is now reserved and unused (formerly deprecated)[30]
  • Value of {{code|2=cpp|1=__cplusplus}} changed to {{code|2=cpp|1=201703L}}[31]
  • Exception specifications were made part of the function type[32]

Library

  • Most of Library Fundamentals TS I, including:[33][34]
    • std::string_view, a read-only non-owning reference to a character sequence or string-slice[35]
    • std::optional, for representing optional objects, a data type that may not always be returned by a given algorithm with support for non-return
    • std::any, for holding single values of any type
  • std::uncaught_exceptions, as a replacement of std::uncaught_exception in exception handling[36][37]
  • New insertion functions try_emplace and insert_or_assign for std::map and std::unordered_map key-value associative data structures[38][39]
  • Uniform container access: std::size, std::empty and std::data[39][40]
  • Definition of "contiguous iterators"[39][41]
  • A file system library based on boost::filesystem[42]
  • Parallel versions of STL algorithms[43]
  • Additional mathematical special functions, including elliptic integrals and Bessel functions[44]
  • std::variant, a tagged union container[45]
  • std::byte, allowing char to be replaced for data types intending to model a byte of data as a byte rather than a character[46]
  • Logical operator traits: std::conjunction, std::disjunction and std::negation[47]

Compiler support

  • GCC 8 has complete (but experimental){{Clarify|reason=How is it complete but experimental?|date=October 2018}} support for C++17.[48][49]
  • Clang 5 and later implement all the features of C++17.[50]
  • Visual Studio 2017 15.7 (MSVC 19.14) supports almost all of C++17.[51][52]

See also

  • C++ compilers
  • C11 (C standard revision)
  • C18 (C standard revision)

References

1. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4661.html|title=N4661 Editors' Report -- Programming Languages -- C++|access-date=2017-03-21|date=21 March 2017}}
2. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4660.pdf|title=ISO/IEC DIS 14882: Programming Languages — C++|deadurl=yes|archiveurl=https://web.archive.org/web/20170325025026/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4660.pdf|archivedate=2017-03-25|df=}}
3. ^{{cite web|url=https://herbsutter.com/2017/09/06/c17-is-formally-approved/|author=Herb Sutter|title=C++17 is formally approved}}
4. ^{{cite web|url=https://www.iso.org/standard/68564.html|title=ISO/IEC 14882:2017}}
5. ^https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"
6. ^{{cite web|url=https://isocpp.org/std/status|title=Current Status : Standard C++|publisher=}}
7. ^{{cite web|url=https://botondballo.wordpress.com/2017/08/02/trip-report-c-standards-meeting-in-toronto-july-2017/|title=Trip Report: C++ Standards Meeting in Toronto, July 2017|date=2 August 2017|publisher=|accessdate=11 January 2018}}
8. ^{{cite web|title=N3981: Removing trigraphs??! (Richard Smith)|url=http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3981.html|date=2014-05-06}}
9. ^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
10. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4190.htm|title=N4190: Removing auto_ptr, random_shuffle(), And Old <functional> Stuff (Stephan T. Lavavej)}}
11. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3928.pdf|title=N3928: Extending static_assert, v2 (Walter E. Brown)}}
12. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4051.html|title=N4051: Allow typename in a template template parameter (Richard Smith)}}
13. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3922.html|title=N3922: New Rules for auto deduction from braced-init-list (James Dennett)}}
14. ^{{cite web|title=Updates to my trip report|url=http://isocpp.org/blog/2014/11/updates-to-my-trip-report}}
15. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4230.html|title=N4230: Nested namespace definition (Robert Kawulak, Andrew Tomazos)}}
16. ^{{cite web|url=http://isocpp.org/files/papers/n4266.html|title=N4266: Attributes for namespaces and enumerators (Richard Smith)}}
17. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4640.pdf|title=N4640: Working Draft, Standard for Programming Language C++|pages=193–195}}
18. ^{{cite web|url=http://isocpp.org/files/papers/n4267.html|title=N4267: Adding u8 character literals (Richard Smith)}}
19. ^{{cite web|url=http://wg21.link/p0245r1|title=Hexadecimal floating literals for C++|author=Thomas Köppe}}
20. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf|title=N4659: Working Draft, Standard for Programming Language C++|at=§5.13.4}}
21. ^{{cite web|url=http://isocpp.org/files/papers/n4268.html|title=N4268: Allow constant evaluation for all non-type template arguments (Richard Smith)}}
22. ^{{cite web|url=http://isocpp.org/files/papers/n4295.html|title=N4295: Folding expressions (Andrew Sutton, Richard Smith)}}
23. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf|title=N4659: Working Draft, Standard for Programming Language C++|at=§9.4.1}}
24. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf|title=N4659: Working Draft, Standard for Programming Language C++|at=§11.5}}
25. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r1.html|title=Selection statements with initializer|publisher=}}
26. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0035r4.html|title=Dynamic memory allocation for over-aligned data}}
27. ^{{cite web|url=https://en.cppreference.com/w/cpp/language/class_template_argument_deduction|title=Class template argument deduction}}
28. ^{{cite web|url=https://www.youtube.com/watch?v=UDs90b0yjjQ|title=CppCon 2018: Timur Doumler “Class template argument deduction in C++17”}}
29. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4640.pdf|title=N4640: Working Draft, Standard for Programming Language C++|pages=431–433}}
30. ^{{cite web|url=https://en.cppreference.com/w/cpp/keyword/register|title=C++ Keywords: register}}
31. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf|title=N4659: Working Draft, Standard for Programming Language C++|at=§19.8}}
32. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0012r1.html|title=P0012R1: Make exception specifications be part of the type system, version 5}}
33. ^{{cite web|title=Adopt Library Fundamentals V1 TS Components for C++17 (R1)|url=https://isocpp.org/files/papers/p0220r1.html}}
34. ^{{Cite web|url=https://isocpp.org/std/status|title=Current Status|last=|first=|date=|website=|publisher=|access-date=}}
35. ^{{Cite web|url=http://en.cppreference.com/w/cpp/string/basic_string_view|title=std::basic_string_view - cppreference.com|website=en.cppreference.com|access-date=2016-06-23}}
36. ^{{cite web|url=http://isocpp.org/files/papers/n4259.pdf|title=N4259: Wording for std::uncaught_exceptions (Herb Sutter)}}
37. ^{{cite web|title=New core language papers adopted for C++17|url=https://isocpp.org/blog/2014/11/new-papers-adopted-for-cpp17}}
38. ^{{cite web|url=https://isocpp.org/files/papers/n4279.html|title=N4279: Improved insertion interface for unique-key maps (Thomas Köppe)}}
39. ^{{cite web|title=New standard library papers adopted for C++17|url=https://isocpp.org/blog/2014/11/new-standard-library-papers-adopted-for-cpp17}}
40. ^{{cite web|title=N4280: Non-member size() and more (Riccardo Marcangelo)|url=https://isocpp.org/files/papers/n4280.pdf}}
41. ^{{cite web|title=N4284: Contiguous Iterators (Jens Maurer)|url=https://isocpp.org/files/papers/n4284.html}}
42. ^{{cite web|title=Filesystem Library Proposal (Beman Dawes)|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3505.html}}
43. ^{{cite web|title=The Parallelism TS Should be Standardized|url=https://isocpp.org/files/papers/P0024R2.html}}
44. ^{{cite web|title=Mathematical Special Functions for C++17, v5|url=https://isocpp.org/files/papers/P0226R1.pdf}}
45. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf|title=N4659: Working Draft, Standard for Programming Language C++|at=§23.7}}
46. ^{{cite web|url=http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0298r3.pdf|title=A byte type definition}}
47. ^{{cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf|title=N4659: Working Draft, Standard for Programming Language C++|at=§23.15.8}}
48. ^{{cite web|url=https://gcc.gnu.org/projects/cxx-status.html|title=C++ Standards Support in GCC - GNU Project - Free Software Foundation (FSF)|website=gcc.gnu.org}}
49. ^{{cite web|url=https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html|title=Chapter 1. Status|website=gcc.gnu.org}}
50. ^{{cite web|url=https://clang.llvm.org/cxx_status.html|title=Clang - C++17, C++14, C++11 and C++98 Status|website=clang.llvm.org}}
51. ^{{cite web|url=https://docs.microsoft.com/en-us/cpp/visual-cpp-language-conformance|title=Visual C++ Language Conformance|first=|last=corob-msft|website=docs.microsoft.com}}
52. ^{{cite web|url=https://blogs.msdn.microsoft.com/vcblog/2018/05/07/announcing-msvc-conforms-to-the-c-standard/|title=Announcing: MSVC Conforms to the C++ Standard|publisher=}}
{{C++ProLang}}

4 : C++|Programming languages|Programming language standards|Articles with example C++ code

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/23 5:28:12