Partners: KDAB Whole Tomato Software CppDepend

22 October 2018

Five Awesome C++ Papers for San Diego

In two weeks there will be a next C++ Committee meeting. This time the group of C++ experts will travel to San Diego, and they will discuss the shape of the upcoming C++ Standards. As far as I know, the meeting will hold a record in the number of submissions (276 proposals!) So it seems that the session will be quite exhausting :)

Here’s my list of five exciting papers that will be discussed during the meeting. I tried to pick something less popular, and usually smaller than significant features like modules, concepts or ranges.

What’s Already in C++20

Before I show you the list, it’s a good chance to mention what’s already voted into C++20.

Added in Albuquerque, November 2017:

  • operator<=> (aka the spaceship operator) and library support for operator<=> P0515
  • Range-based for with initializer P0614
  • Apply [[nodiscard]] to the standard library - P0600
  • std::osyncstream P0053
  • constexpr std::complex
  • constexpr algorithms P0202
  • Floating point std::atomics P0020
  • std::string/std::string_view .starts_with() and .ends_with() P0457

Gathered from 2017 Albuquerque ISO C++ Committee Reddit Trip Report : r/cpp

Another meeting, Jacksonville, March, 2018:

  • Make typename optional in more places
  • [[likely]] , [[unlikely]] and [[no_unique_address]] - attributes
  • <version> header
  • Calender and timezone library - big and nice addition to STL - P0355
  • syncstream manipulators for C++ Synchronized Buffered Ostream
  • span P0122
  • [Pack expansion in lambda init-capture: ...args = std::move(args)](){} P0780

More info: 2018 Jacksonville ISO C++ Committee Reddit Trip Report : cpp

And the most recent one, June 2018, Rapperswil:

  • Contracts P0380
  • Standard library concepts P0898
  • Class non type template parameters (NTTP)P0732
  • Feature test macros P0941
  • Conditional explicit P0892
  • Virtual calls in constant expressions P1064
  • atomic_ref P0019
  • shift_left and shift_right algorithms P0769
  • type_identity P0887
  • ispow2, ceil2, floor2, log2p1 P0556
  • bit_cast P0476
  • Remove facilities deprecated in C++17 P0619

Gathered from 2018 Rapperswil ISO C++ Committee Trip Report, r/cpp

You can always find the list of ISO meetings here:
Upcoming Meetings, Past Meetings : Standard C++

The list

The papers (mailings) for the upcoming San Diego meeting can be found under the following link:
ISO/IEC JTC1/SC22/WG21 - Papers 2018

Or in two sections posted at isocpp.org:

But there’s one handy summary that you might want to read. Ben Craig with the help of other was so kind to group papers into areas that are easier to follow:
San Diego Paper Reading Guide - Google Groups

Ok, so below you can find my list of papers that brought my attention:

constexpr string & vector

One of the plans for future C++ is the ability to call most of the things… or even all of the things at compile time. Currently, we have constexpr that you can apply in many places, in C++20 there are also algorithms that will be constexpr (see P0202), but still there are some complications with advanced code - especially regarding allocations, exceptions and few other issues.

They are all based on More constexpr containers- P0784.

Some of the issues:

  • Dynamic allocations inside containers. With new at compile time, the compiler would allocate memory and then “write” it into the binary segment of a program.
  • reinterpret_cast calls
  • exceptions and assertions
  • debug checks

The whole plan for “constexpr all the things” is also described in a recent Luis Dione’s talk:

CppCon 2018: Louis Dionne “Compile-time programming and reflection in C++20 and beyond” - YouTube

I hope that the speed of compilation of the projects will still be faster… not 10x slower :)

Structured Bindings Improvements

Structured Bindings are a bit magical at the moment.

auto [x, y, z] = Compute();

x, y, z are just names ( or bindings) and they are a bit restricted. You cannot use them as real variables. For example, you cannot declare them as static, use them in lambda captures or make it constexpr.

The paper proposes some fixes and clarifications:
Extending structured bindings to be more like variable declarations - P1091

Pattern Matching

Something more than basic if or switch statements:

For example:


struct visitor {
   void operator()(int i) const {
       os << "got int: " << i;
    }
    void operator()(float f) const {
        os << "got float: " << f;
    }
    std::ostream& os;
};
std::visit(visitor{strm}, v);

Could be written in a much nicer form, by using new pattern inspect:

inspect (v) {
    <int> i: strm << "got int: " << i;
    <float> f: strm << "got float: " << f;
}

This could also be extended for strings:

inspect (s) {
    "foo": std::cout << "got foo";
    "bar": std::cout << "got bar";
    _: std::cout << "don't care";
}

And also tuples, etc.!
This seems to be a compelling technique and a lot of people complain that C++ has no support for such expressions.

Pattern Matching P1260

Text Formatting

Easy and powerful text formatting support:

string message = format("The answer is {}.", 42);

This is based on a quite popular {fmt} library: fmt by Victor Zverovich

Text Formatting P0645

Concurrent Data Structures

A concurrent associative data structure with an unsynchronised view p0652

You can find a reference implementation: GitHub - STL compatible implementation of hash map optimised for concurrent access

The idea is the following: multiple operations on unordered containers make sense only if that container is not concurrently modified. A user may take the responsibility that no-one is modifying the container at this point and gain all the operations and iterators.

Extra Papers & Mentions

  • Integrating simd with parallel algorithms P0350R2
  • Changes between C++11 and C++14: Changes between C++11 and C++14 - if you want to refresh your memory :)
  • 2D Graphics Back Again! P0267 & P1200 - the paper is not dead, and there are still discussions around that!
    I’m waiting for the cppcon 2018 talk from Guy Davidson describing the library. It’s easily available in vcpkg, and I really need to try this library out soon.

Summary

Reading papers is actually another way of learning C++. A lot of documents have proper introductions and reasoning so you can learn about the current limitations of the language and the library.

As I mentioned, in the beginning, my list is very subjective. And I only picked a few papers out of 250+! I’d be interested in your picks. What got your attention? What would you like to see in the new Standard?

Get my free ebook about C++17!

More than 50 pages about the new Language Standard.

C++17 in detail, by Bartlomiej Filipek

© 2017, Bartlomiej Filipek, Blogger platform
Any opinions expressed herein are in no way representative of those of my employers.
This site contains ads or referral links, which provide me with a commission. Thank you for your understanding.