Journal Articles
Browse in : |
All
> Journals
> CVu
> 315
(7)
All > Topics > Programming (877) Any of these categories - All of these categories |
Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.
Title: The Standard Report
Author: Bob Schmidt
Date: 03 November 2019 18:14:18 +00:00 or Sun, 03 November 2019 18:14:18 +00:00
Summary: Guy Davidson reports from the C++ Standards Committee.
Body:
In this report I’m going to cover the new language proposals that were voted into the standard at the recent meeting in Cologne. Thirty-two motions came before the committee from the Library Working Group (LWG) for voting. Rather than iterate through them all, I shall present some highlights. Recall that any paper can be reviewed by visiting wg21.link and appending the proposal number, for example https://wg21.link/P1000.
P0645 was a particular favourite of mine. While iostreams is the recommended API for reasons of extensibility and type safety, printf
offers advantages such as the separation of formatting arguments and more compact source and binary code. However, this paper proposes a new text formatting library that can be used as a safe and extensible alternative to the printf
family of functions. It is intended to complement the existing C++ I/O streams library and reuse some of its infrastructure such as overloaded insertion operators for user-defined types. The example message looks like:
string message = format("The answer is {}.", 42);
As a mathematician, I was delighted by the passing of P0631, Math(s) constants. This proposal introduces a new namespace, std::numbers
, and populates it with thirteen new constants. From the paper:
The library-defined partial specializations of math constant variable templates are initialized with the nearest representable values of e, log2e, log10e, π, 1/π, 1/√π, ln2, ln10, √2, √3, 1/√3, Euler-Mascheroni γ constant, and golden ratio ϕ constant (1+√5)/2.
One paper that got in just under the wire was P1754, ‘Rename concepts to standard_case for C++20, while we still can’. Concepts are one of the big ticket features for C++20, having nearly made it into C++11, and the habit has been to name concepts Using Leading Capitals, unlike the rest of the standard which uses_space_case for its identifiers. There was a session of LEWG to decide on the sixty-eight new names and to resolve the accompanying naming collisions caused by migrating a big pile of identifiers to standard format.
If you are familiar with three-way comparison through operator <=>
, also known as the spaceship operator because of its resemblance to a piece of ASCII art videogame heritage, you will know that it has broad application throughout the standard library. P1614 is the paper which makes ALL the changes necessary to make this happen. It is the work of Barry Revzin and an excellent piece of stable-cleaning: a fairly dull and error prone task that has been well-executed.
Modules have precipitated a change to the way we think about headers. It is obvious that we need a natural and portable mechanism to import the standard library into a modules-enabled compilation. To do this, we want to provide a minimal, uninventive mechanism to expose the existing standard library organization to modular compilations, not get in the way of, or create any impediment to, a proper reorganization of the standard library into named modules, and reserve space for such a future reorganisation. This is met by P1502, which reserves module names beginning with std
. While it is easy to assume that nobody would do a thing like that, the standard now prevents you from doing so; otherwise your program is ill-formed.
Two dramatic papers cross a large bridge towards constexpr compilation by making string and vector constexpr. This is the work of Louis Dionne and seems at first glance to be rather counterintuitive: how does one allocate at compile time? However, with the loosening of requirements on constexpr in P0748 and related papers we can make it so. There is good reason to do so: these containers will be very useful in the reflection efforts currently under way for standardisation. P0980 deals with std::string
, while P1004 deals with std::vector
. The wording is very simple: add constexpr to the front of each declaration.
Some interesting issues were encountered while reviewing the implementations in libc++. For std::string
, small string optimisation might be thought to complicate matters but it is implemented using unions, rather than reinterpret_cast
which would render it unavailable for constexpr. Also, char_traits
needs to be constexpr for at least its char
specialisation. Meanwhile, std::vector
uses try
catch
blocks, which aren’t permitted in constexpr expressions; there is a paper in flight, P1002, which might assist this but it has yet to make the standard and is unlikely to reach C++20. No doubt the implementers will come up with a solution.
One of my pet peeves with the standard library is the return type of size()
. It’s an unsigned integer, which is inconsistent with the advice on the use of unsigned. The design of span was such that its size would return a signed integer, which pleased me greatly, but this decision was overturned in Rapperswil 2018. Despite pleading and protestation, in the name of consistency, P1523 makes size()
return an unsigned integer. At least we have ssize()
.
A whole new header was introduced to the standard by P1208. The header is called source_location
which introduces a struct by that name. One of the goals of the committee in recent years has been to reduce dependency on the pre-processor. The introduction of modules has gone a considerable way towards this by eliminating the need for #include
. P1208 provides an alternative to __FILE__
and __LINE__
, as possibly suggested by this identifier. It also offers the function name and the column number: I look forward to seeing what that might enable.
Finally, there was the motion from WG21 itself, rather than from any of the working groups:
Move to appoint an editing committee composed of Daniel Kruegler, Davis Herring, Nina Ranns, and Ville Voutilainen to approve the correctness of the C++ working paper as modified by the motions approved at this meeting, and to direct the Convener to transmit the approved updated working paper for CD ballot.
C++20 is ‘complete’ and the next stage is to send it to the National Bodies for comments. These NB comments will be discussed at the next meeting in Belfast.
Normal business will still be carried out in Belfast and I’ll report on that, but there will also be interesting procedural matters as NB comments are resolved. They will take priority over paper review since we must produce a draft for the National Bodies to agree to at the end of Belfast if we are to finalise the standard in Prague and send it to ISO for publication.
Stay tuned for more procedural detail.
is the Principal Coding Manager at Creative Assembly. He has been writing games for about 75% of his life now. He is climbing through his piano grades and teaching Tai Chi while parenting in Hove and engaging in local political activism.
Notes:
More fields may be available via dynamicdata ..