Browse in : |
All
> Journals
> CVu
> 296
|
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: Standards Report
Author: Bob Schmidt
Date: 02 January 2018 16:48:15 +00:00 or Tue, 02 January 2018 16:48:15 +00:00
Summary: Emyr Williams updates us on the latest in C++ standardisation.
Body:
He’s probably best known as ‘the guy who interviews people for CVu’, but he branched out by responding to a call for volunteers to be the new ACCU Standards Officer. Emyr is interested in C++, and as an attendee of the BSi C++ Panel in London, felt volunteering seemed the logical choice. He volunteered so he could learn more about C++, and how a language is put together; the role will also force him to be a better programmer, and gain a deeper knowledge of the language.
The last ISO C++ Committee meeting was held in Albuquerque, New Mexico for six days in November, hosted by the folks at Sandia National Laboratories, and by all accounts was quite a busy week with around 140 people in attendance representing 10 national bodies. [1] [2]
Allow me to start with a caveat: I found it’s quite difficult to write a report for a meeting you didn’t attend, but thanks to numerous blog posts and articles online, I’m able to provide something of a digest of the meeting. While I cannot comment on the atmosphere at the meetings, I can comment on what the outcomes were and where C++ is headed. Additional contributions were made to the report by Guy Davidson and Roger Orr, and are accredited accordingly.
As Roger mentioned in his previous standards report, the ISO voting was still ongoing for the draft International Standard for C++ 17; however, I’m happy to report that the draft was accepted, and that we do now in fact have C++ 17. Which is great news. In terms of compilers, the latest versions of both GCC and Clang have complete support for C++17, and MSVC expects to be feature complete by March 2018.
One of the primary goals of the meeting was to address the comments that the national bodies had sent in, in regards to the Modules TS comment ballot. These were addressed in a single meeting. The main area for additional work was when entities were implicitly exported from a module – for example return types of functions. The discussions on modules are still on going but it’s hoped that it will make it in to C++ 20.
It was also the second time that changes to the current C++ 20 draft could be voted on. And some of the highlights include (in no particular order…):
Range-based for statements with an initializer (p0614r1)
This allows you to initialise an object within the parenthesis of the for
loop [3]. The benefit is that it allows the developer to use locally scoped variables, so for example, you could do something like this:
for( T widgets = getWidgets() ;
auto& w : widgets.items())
{
// do stuff here…
}
Whereas before you’d have to do something like this:
{ T widgets = getWidgets(); for(auto& w : widgets.item()) { // it's worth noting that // for(auto & w : w().items())" is wrong } }
This change makes the range-based for
loop consistent with other control flow statements such as if
and while
, which gained the facility to contain variable initialization before their condition in C++ 17. A simple example would be if you had a vector that you wanted to populate then loop over, you could do it all in the parenthesis of the for
loop.
Consistent comparison (spaceship operator) (p0515r3 )
One of the more significant features voted in was Herb Sutter, Jens Maurer and Walter E. Brown’s proposal for consistent comparison [4], which is also known by colloquially as the spaceship operator, or operator<=>
.
There had been previous efforts and proposals to create a Consistent Comparison proposal which all served as the basis of the paper as proposed. The proposal sought to pursue three-way comparison, by allowing default copying to guide default comparison, and it would allow developers to write a memberwise comparison function body far easier than it is at present, and to enable more powerful and precise comparisons, with less code.
The paper gave two cases, the common case, where if you wanted to write all comparisons for your type X with type Y with memberwise semantics, all you needed to write would be :
auto X::operator<=>(const Y&) = default;
And that’s it! Whereas previously you’d need to write:
class point{ int x; int y; public: friend bool operator==(const Point& a, const Point& b) { return a.x == b.x && a.y == b.y; } friend bool operator< (const Point& a, const Point& b) { return a.x <b.x || (a,x == b.x && a.y < b.y); } // you'd still need to write another 4 // of these operator overloads! }
Herb Sutter has an excellent example on his trip write up comparing two case insensitive strings. [5]
Modules TS
At the last meeting (Toronto), the Modules TS was published and circulated for balloting, which is where national bodies could vote, and submit comments on the TS. The ballot did pass, but there were numerous technical comments that were worked through during the meeting. Progress was made, but not enough to publish a final TS at the end of the meeting. I believe there are teleconference meetings taking place over the coming few months to work on this, and an update will follow in due course.
There were a couple of planned TS’s proposed as well, these do not have an official project or a working draft at the time of writing.
Library
The Library Working Group (LWG) discussed how Concepts should be used in the C++ library. The consensus was that a full proposal would need to be seen at a future meeting before Concepts are to be used in future proposals.
The LEWG approved proposals which are mainly aimed at C++ 20, and were sent to the LWG for a wording review. These proposals included:
std::polymorphic_value<T>
(p0201r2)<version>
(p0754r1)- Calendars and Timezones (p0355r4)
std::hash_combine
(p0814r0)- Bit operations (
rotr
,popcount
etc) (p0553r2) - Integral power-of-2 operations (p0556r2)
- Efficient access to basic
std::stringbuf
’s buffer (p0408r3) std::bind_front
(p0356r3)std::spanstream
(p0448r1).contains()
forstd::map
(p0458r0)
The following proposals were discussed and given design feedback and guidance from the group:
std::transform_if
(p0838r0): Brings the implementation oftransform_if
from boost (boost/compute/algorithm)std::flat_map
(p0429r3)A more space/runtime efficient representation of a map structure. Commonly used in gaming, embedded or system software development. Its intention is that the
flat_map
is a drop-in replacement forstd::map
but with different time and space efficiency properties. It’s primarily based on Boost’sflatMap
, and its API is nearly identical tostd::map
.std::function_ref
(p0792r0)The idea behind
function_ref
is allow further functional programming idioms to be added to the language. ‘Higher-order’ functions are one of the key areas of this paradigm; essentially, they are functions that take functions as arguments, and can return functions as results. At present, the language doesn’t support referring to an existing Callable object, or at least not flexibly at any rate. The proposal hopes to change that.std::wide_int
(p0539R2)There’s no cross-platform solution to have bigger numbers than
int64_t
. While there’s the non-standard type__int128
which is provided by GCC and clang, there is no other way to do this. The paper proposes a templated class where you can specify the size of integer you want: e.g.std::wide_uint<128> veryBigNumber;
- Endian support (p0803r0)
At the moment, there’s no standardised way to handle endianness in C or C++. Some platforms provide a mechanism for this in C, it varies between platforms. The paper was written to determine whether or not there was interest in adding this to the C++ STL or a library TS.
Details are available online of all the papers being discussed by the committee. [6]
References
[1] https://botondballo.wordpress.com/2017/11/20/trip-report-c-standards-meeting-in-albuquerque-november-2017/
[2] https://www.reddit.com/r/cpp/comments/7ca2sh/2017_albuquerque_iso_c_committee_reddit_trip/
[3] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0614r1.html
[4] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0515r3.pdf
[5] https://herbsutter.com/2017/11/11/trip-report-fall-iso-c-standards-meeting-albuquerque/
[6] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/#mailing2017-11
Notes:
More fields may be available via dynamicdata ..