C++ Annotated: January – May 2018

Hi,

We are glad to share with you another edition of C++ Annotated, filled with the most important and interesting news around the C++ community over the last 5 months. In this edition:

Language standardization news

ISO C++ Committee – Jacksonville

cpp_logoA regular C++ committee meeting was held this March in Jacksonville, Florida. C++20, currently the main topic up for discussion in the Committee, is planned to be feature-complete in the spring of 2019, at the meeting in Kona, Hawaii. Concepts and Ranges are doing well and most likely will be signed for C++20, but Modules, Coroutines, and Contracts are way behind. Still, if we take a broader look at what’s probably going to land in C++20, it seems there’s a lot! Calendar and timezone library, compile-time programming milestones (here we mean, of course, standard containers in constant expressions), new attributes ([[no_unique_address]] for potentially empty objects, [[likely]] and [[unlikely]] for branches to provide extra information for the optimizer), symmetry for <=> operator, and many others.

If you are interested, we recommend going through some of the trip reports below for more details:

  • By Herb Sutter – detailed overview with all the necessary links from the Committee Chair
  • By Bryce Lelbach – basic overview of the most important facts and decision on Reddit
  • By Timur Doumler – trip report by a JetBrains representative mostly focusing on language toolability as the main target
  • And other reports, all definitely interesting and highlighting various aspects of the meeting and the language-related discussions held in Jacksonville: Vittorio Romeo, Jason Merrill, Botond Ballo, and J. Daniel García.

Conferences

ACCU 2018

accu_logo
Bristol hosted the yearly ACCU Conference in April. While historically ACCU has been focused on C++, it’s now a conference about Professionalism in Programming and as such offers wider topic selection. This makes it a unique event with a mix of hardcore C++ topics like “Zero-allocation & no type erasure futures” by Vittorio Romeo, “These 10 tricks that only library implementers know” by Marshall Clow (Qualcomm) and Jonathan Wakely (Red Hat), “Class Template Argument Deduction in C++17” by Timur Doumler, “Nothing is better than copy and move” by Roger Orr, and many others. It also included talks and workshops on Rust, Swift, and more general topics on Code Reviews, Continuous Delivery, and various architectures.

Lisa Lippincott’s keynote talk entitled “The Shape of a Program” was dedicated to topology-based approach to programming, which may be helpful for formal verification of code. Hadi Hariri in his keynote, “Kotlin/Native – Embracing existing ecosystems”, talked about bringing our new JVM and Android language, Kotlin, to a variety of native platforms via LLVM. The full video playlist is available, and you’re welcome to read our trip report too.

C++ Russia 2018

cpp_russiaC++ Russia was held in St. Petersburg this year, presenting a great mix of famous international speakers speaking in English, on the one hand, and the brightest minds of the Russian-speaking C++ community, on the other. The former included Jon Kalb, the organizer of the two most famous C++ events in the world, CppCon and C++Now, with his historical sketch on C++: “C++ Today: The Beast is Back”. Herb Sutter also made an appearance with his talk on the spaceship operator via Skype, as did Jonathan Boccara with 105 STL algorithms, Andrei Alexandrescu discussing design techniques to improve algorithms for better performance, and Simon Brand speaking on Modern C++ Parallelism, among other renowned community names. Other talks were given in Russian and covered topics like memory organization, CMake tips and tricks, various aspects of static analysis, Android NDK crash reports, actors model, and more. Videos from this year are not yet available, but will be uploaded to this YouTube channel later.

C++Now 2018

cpp_nowVery academic and deeply thoughtful as usual, C++Now was back to Aspen in the beginning of May. This is a conference about the future of C++ which encourages all the attendees to participate in hot discussions about the C++ of tomorrow. At the altitude of 2,400 meters, C++Now offers limited oxygen but unlimited C++ insights.

This year’s two keynotes included Lisa Lippincott’s “The Shape of a Program” and John Regehr’s “Undefined Behavior and Compiler Optimizations,” both inspiring and practically useful to an extent. Other exciting topics were discussed:

  • Smart output operators by Jonathan Boccara, with performance comparison of ranges, STL algorithms, and smart output operators.
  • Initializer lists issues by Jason Turner; the group discussion offered more insights than the lecture did.
  • Inspiring findings by Matt Godbolt (“What Else Has My Compiler Done For Me Lately?”) as a continuation of his keynote talk from CppCon 2017.
  • Philosophical discussions by Ben Deane on Declarative Style in C++ and Titus Winters on Modern C++ API Design.
  • A slightly crazy experiment in template metaprogramming by Odin Holmes (“C++ Mixins: Customization Through Compile Time Composition”), and many others.

You’re welcome to read the JetBrains trip report as well as others linked to the post with the official C++Now 2019 announcement. Watch these videos on YouTube as well.

Learning

C++ talks you can’t miss

matt_cppcon
If you’re looking for useful C++ video content on particular topics or just in general, to learn more about the language, this reddit post will brings dozens of new ideas to the table. It lists many bright C++ talks which, from the community’s point of view, you simply must watch. Matt Godbolt’s keynotes on compiler explorer findings, Sean Parent’s talk on Better Code, super inspiring talks by Kate Gregory (especially Stop Teaching C), Herb Sutter’s keynotes, Eric Niebler’s Ranges talk, and of course Tony Van Eerd’s Postmodern C++. Just be careful, as looking through this awesome list you might feel sad you don’t have enough time to watch all of the talks. You’ve been warned.

One Like, One C++ Tip/Fact

brand_thread
Simon Brand started a fantastic thread in Twitter in February, collecting tips and facts about C++. Here are a few sample tips:

  • #5 Tip: Union punning is okay in C, but undefined behavior in C++. Use memcpy or C++20’s bit_cast for a safe alternative. Check the assembly if you’re worried about perf impact.
  • #67 Tip: C++17’s std::string_view can replace many instances of std::string const& parameters, but if you’re going to create a std::string anyway, you may as well put that in your interface to avoid unnecessary allocations.
  • #709 Tip: You can’t SFINAE copy/move constructors/assignment operators because they cannot be templates. You can instead inherit from a class template which conditionally defines or deletes those special members.

His facts are both fun and useful, too:

  • #6 Fact: According to @meetingcpp, there are 106 C++ User Groups in the world. Consider starting one in your community! It’s a great way to practice public speaking and learn new things.
  • #70 Fact: if constexpr is far more constrained than D’s static_if; each branch has to have some valid instantiation and you can’t use it to conditionally remove member variables and whatnot.

Effective search for a string pattern

gcc_bug
Someone asked on reddit, “Why are the new C++17 searchers slower than glibc or musl’s memmem()?” The performance comparison is indeed unexpected. They searched a binary file with an 8 MB buffer for a 111-byte pattern where the first 110 bytes would match, but the last wouldn’t. They compared memmem function, std::default_searcher, std::boyer_moore_searcher and std::boyer_moore_horspool_searcher. Surprisingly, memmem won by a large margin! The answer to this conundrum was found in the thread, and even led to a bug report to GCC. It turned out that no specialization was implemented for std::boyer_moore_searcher for an array of std::bytes. There is one for integral types, which std::bytes is not.

Rename in C++ code

refactor_test_suiteRichard Thomson is an author of a testing suite for C++ refactoring tools. He’s checked a bunch of tools in the past (and more are planned) and posted detailed results in his repository on GitHub. In March, he posted about comparing a single refactoring – Rename – in Visual Studio 2017 Community Edition 15.5.7 and in ReSharper C++ 2017.3.2.

As Richard notes in his blog post, naming things is hard. Developers rarely come up with a good choice from the very first line of code. Additional issues arise when the responsibility of a code piece changes. When done manually, renaming is risky and unreliable; text editors that aren’t aware of semantics don’t do much better.

Richard’s text suite incorporates over 600 test cases for renaming identifiers. Here’s a short summary of the batting averages he’s measured for Visual Studio and ReSharper C++:

  • VS passes 457 out of 602 test cases, which is a 76% accuracy rate.
  • R++ passes 591 out of 602 test cases – a little over 98%.

Do check out the full story in Richard’s blog post if you are interested in refactoring identifiers effectively.

Const: East vs West

constIn the last few months, a heated discussion has flared up about which const position is more accurate and reasonable. East const vs West const discussion is a new C++ trend. There are even wristbands printed for both groups (though some community members wear both). And even while C++ Core Guidelines are against the East const, they admit it’s a more logical position. Who is right? Or, to put it another way, is anyone actually ‘right’ in this discussion? For the East Const position, check out Jon Kalb’s blog post and his lightning talk recording on East Const. To get the opposite view, wait for Jonathan Müller’s “A Fool’s Consistency,” the lightning talk recording from C++Now 2018, which was recognized as the Best Lightning Talk of the event, to become available for viewing.

Simplify code with if constexpr

constexpr
Bartlomiej Filipek demonstrated the benefits of if constexpr in his blog as applied to comparing numbers and a factory with a variable number of arguments. Explaining the need for a compile time mechanism (to avoid compiling unmatching code at all) and showing the working but somewhat complicated syntax of enable_if solution, the author rewrites both samples in C++17 using if constexpr.

std::iterator is deprecated

fluent_cppIn his blog post, Jonathan Boccara explains the reasoning behind the deprecation of std::iterator and what we can use instead. Even if you are not using C++17 in production or don’t create operators, this post is still useful! The deprecation of std::iterator doesn’t affect the two major working principles of iterators described in the blog post, which are good to understand:

  • the types that the STL expects from an iterator are still necessary, and
  • the idea that an iterator should provide information to the code that uses it is still valid.

Besides, you may find it surprising (but useful) to learn that the std::iterator_traits implementations in libstdc++ that gcc uses is different from the one in libc++ used by clang!

C++17 by example

tony_sample
If you prefer learning languages by example, don’t miss what Tony Van Eerd has in store. Most C++17 features as presented in “Tony Tables” can be found in Tony’s GitHub repository. Samples that are easy to follow explain if with initializer, structured bindings, constexpr If, fold expressions, and many others. Tony points you to the C++14 implementation and the C++17 table, so that you can compare and better understand the reasoning behind the change. Many thanks for such a great learning tool, Tony!

C++ Foundation Developer Survey

survey_foundation
C++ Foundation has held their annual C++ Developer Survey. The idea is to get more information on what the community uses or want to use in terms of C++. This covers topics from language features to language-related tooling and techniques. C++ Foundation plans to repeat this survey every year. This year’s results are calculated based on 3,286 responses and show the following:

  • The most popular target platforms for C++ development are desktop Linux and Windows.
  • The most popular complimentary language to C++ is Python.
  • The most popular code analysis tool is Clang Static Analyzer.
  • The most popular IDE is Visual Studio (but we were happy to see CLion in 5th place!).

By the way, we’re about to publish the results of the JetBrains Developer Ecosystem survey, and when that’s done, you’ll have an additional perspective on the latest C++ trends.

Having fun

C++ Code That Print 42

42
In this new section of our C++ Annotated, we’d like to share some geek culture posted by Jonathan Boccara in his Fluent{C++} blog. It’s dedicated to the Towel Day (yearly tribute to The Hitchhiker’s Guide to the Galaxy by Douglas Adams). How many beautiful pieces of code in C++ can you write that print the Answer to the Ultimate Question of Life? Jonathan put the word out to the community and received lots of fantastic responses. He has published the most interesting ones in his blog. I personally enjoyed the one from Joe Davis the most, along with the DeepThought::answer function by James M. Which one’s your favorite?

Recent releases

CLion

CLion_400x400_Twitter_logo_whiteCLion v2018.1 was released at the end of March. With this version, C++17 support has come one step closer to being complete. C++17’s if and switch with initializers and its structured bindings are now implemented. Clang-Tidy integration now allows providing settings via a .clang-tidy config as an alternative to the IDE’s UI, while the UI has been improved by adding an ability to set Clang-Tidy options. Windows users may be interested in checking CLion’s improved WSL support. Besides, all users will benefit from the CMake Install action, an ability to open a non-CMake project in the editor, breadcrumbs for navigation, and dozens of other improvements. What is more, CLion can now be used as a Rust IDE since it offers support for Cargo and Rust code debugging (via a non-bundled plugin).

After the 2018.1 release, the CLion team has announced their roadmap for v2018.2 and has already launched the 2018.2 Early Access Program.

ReSharper C++

R++_400x400_Twitter_logo_whiteReSharper C++ has also released its 2018.1 major update. Two most important features of this version include Debug Step Filters to avoid stepping into specific functions during debugging, and Includes Analyzer to investigate the dependencies between header files that affect build times. Other enhancements in this update include: a more user-friendly Go to File Member dialog, the ReSharper command-line code cleanup tool now working for C++ (use it to apply Clang-Tidy fix-its or remove redundant code), and several new interesting code inspections for C++ code.

Visual Studio

vs_cppVisual Studio 2017 version 15.7.0 was released in May. Its most appealing highlights are C++ Core Checks, which are now part of the default toolset for native code analysis, and ClangFormat, which can now be used to format code as you type (with support for different style in different code locations). CodeLens for Unit Tests now lets you run, debug, and view test status in VS. There are also many improvements for iOS and Linux development, and lots of C++17 support enhancements. The full release notes can be found here.

Things are moving quickly, and Visual Studio 2018 v15.8 is already available as a preview. Check out their C++ Quick Info tooltips that expand macros.

Vcpkg on all platforms

vcpkgAnother thing the Microsoft team has announced recently is a single C++ library manager for Linux, macOS, and Windows. It’s Vcpkg, which was previously available only on Windows but is now also available on Linux, Mac, and other POSIX systems. It comes with over 900 libraries on Windows and over 350 libraries for Linux and macOS. You can also use it with WSL.

Qt Creator

qtAnother recent C++ IDE update is Qt Creator 4.6. It comes with C++17 support (thanks to clang-based code model update, but first enable it in settings!), additional code checks from Clang-Tidy and Clazy, enhanced symbol’s informational tooltips which show the actual type for auto variables, template parameters, and the \brief paragraph of a documentation comment.

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

One Response to C++ Annotated: January – May 2018

  1. Tom Hulton-Harrop says:

    I thought this newsletter was brilliant! So much great content! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *