Video of my CppCon 2019 Presentation “C++20 What’s In It For You?”

On September 18th, 2019 I gave a presentation titled “C++20 What’s In It For You?” at CppCon 2019.
You can find the slides here.

The official video is now also available on YouTube. Enjoy 🙂

Share

Slides of my CppCon 2019 Presentation “C++20 What’s In It For You?”

On September 18th, 2019 I gave a presentation titled “C++20 What’s In It For You?” at CppCon 2019.
The slides of my presentation can be downloaded below:

Share

Next BeCPP UG Meeting Planned For October 10th, 2019

The next meeting of the Belgian C++ Users Group is planned for Thursday October 10th, 2019 at 18:00 at Brabanthal (room Luna).

think-cell ( https://www.think-cell.com/ ) is sponsoring this event by providing the location, drinks and catering.

think-cell Logo

The agenda is as follows:

  • 18:00: Reception with food.
  • 18:30: Session 1: C++20: What’s in it for you? (Marc Gregoire)
    With the current three-year pace of C++ releases, the next release is scheduled for 2020, C++20. This presentation gives an overview of what you can expect in the new standard. It starts with discussing the C++20 language features that will be added by the C++20 standard, such as concepts, coroutines, templated lambdas, the spaceship operator, pack expansion in lambda captures, string literals as template parameters, extra initializer for range-based for loop, modules, and more. Next, we’ll delve into the new Standard Library features, such as ranges, std::span, atomic smart pointers, and more. Depending on the outcome of the next C++ Standard Committee meeting, the list of new features might include improved futures, task blocks, and text formatting. If you want a concise overview of what the C++20 standard will offer, then this presentation is for you.
  • 19:30: Break
  • 19:45: Session 2: From Iterators To Ranges — The Upcoming Evolution Of the Standard Library (Arno Schödl)
    Pairs of iterators are ubiquitous throughout the C++ library. It is generally accepted that combining such a pair into a single entity usually termed Range delivers more concise and readable code. Defining the precise semantics of such Range concept proves surprisingly tricky, however. Theoretical considerations conflict with practical ones. Some design goals are mutually incompatible altogether.
  • 20:45: Introduction to think-cell, followed by a drink.
Professional C++, 4th Edition


We will be giving away 2 copies of Professional C++, the 4th Edition.

C++17 Standard Library Quick Reference


We will also give away a copy of C++17 Standard Library Quick Reference.

The event is free for everyone, but you need to register for it.

There are 80 seats available for this event.

Note: The deadline for registrations is October 9th, 2019!

Share

“C++17 Standard Library Quick Reference” Now Available

Together with Peter Van Weert, we finished our new book titled “C++17 Standard Library Quick Reference”. It’s published by Apress.

Abstract

This quick reference is a condensed guide to the essential data structures, algorithms, and functions provided by the C++17 Standard Library. It does not explain the C++ language or syntax, but is accessible to anyone with basic C++ knowledge or programming experience. Even the most experienced C++ programmer will learn a thing or two from it and find it a useful memory-aid.

It is hard to remember all the possibilities, details, and intricacies of the vast and growing Standard Library. This handy reference guide is therefore indispensable to any C++ programmer. It offers a condensed, well-structured summary of all essential aspects of the C++ Standard Library. No page-long, repetitive examples or obscure, rarely used features. Instead, everything you need to know and watch out for in practice is outlined in a compact, to-the-point style, interspersed with practical tips and well-chosen, clarifying examples. 

This new edition is updated to include all Standard Library changes in C++17, including the new vocabulary types std::string_view, any, optional, and variant; parallel algorithms; the file system library; specialized mathematical functions; and more.

What You Will Learn

  • Gain the essentials that the C++ Standard Library has to offer
  • Use containers to efficiently store and retrieve your data
  • Inspect and manipulate your data with algorithms 
  • See how lambda expressions allow for elegant use of algorithms
  • Discover what the standard string class provides and how to use it
  • Write localized applications
  • Work with file and stream-based I/O
  • Prevent memory leaks with smart pointers
  • Write safe and efficient multi-threaded code using the threading libraries

Who This Book Is For

All C++ programmers, irrespective of their proficiency with the language or the Standard Library. A secondary audience is developers who are new to C++, but not new to programming, and who want to learn more about the C++ Standard Library in a quick, condensed manner.

Share

LLVM Meetup, Leuven, 19th of June

The second Belgian LLVM Meetup will take place at the Guardsquare offices in Leuven, the 19th of June. Anyone who’s working with, or is simply interested in, the LLVM project or any of its tools; Clang, lldb, lld, Polly,… is invited. The evening starts off with three short talks on various LLVM related topics. Afterwards, there will be plenty of time to exchange experiences and get to know the local LLVM community.

Schedule:

  • 20h00: Arrival
  • 20h30: Talks ( +- 20min each )
    • Just compile it: High-level programming on the GPU with Julia.
    • Sim: a contract-based programming language for safety-critical software.
    • Processing complete iOS applications on top of LLVM.
  • 21h30: Drinks

More details at: http://meetu.ps/e/GMrp0/BJHXT/f

Share

Next BeCPP UG Meeting Planned For July 3rd, 2019

The next meeting of the Belgian C++ Users Group is planned for Wednesday July 3rd, 2019 at 18:00 at CluePoints @ OFFBar | ONSpace.

CluePoints ( https://cluepoints.com/ ) is sponsoring this event by providing the location, drinks and catering.

CluePoints Logo

The agenda is as follows:

  • 18:00: Sandwiches.
  • 18:30: Session 1: What’s new in Visual C++ 2019? (Marc Gregoire)
    Microsoft Visual Studio 2019 and Visual C++ 2019 come with a host of new features. In this session, we will have a look at the important changes and improvements for C++ developers.
  • 19:30: Break
  • 19:45: Session 2: Statistical Scientific programming: challenges in converting R to C++ (Olivia Quinet)
    Scientific programming is in itself a challenge due to several concomitant issues and requirements including low response time, low memory usage, minimizing numerical errors, error propagation.
    R is a programming language for statistical computation providing a wide set of packages for linear and non linear modeling, statistical tests, …
    This talk will focus on the different Object-Oriented strategies implemented to overcome those challenges, speed up the computation while reducing the memory footprint.
  • 20:45: Introduction to CluePoints, followed by a drink.
Professional C++, 4th Edition


We will be giving away 2 copies of Professional C++, the 4th Edition.

Beginning C++17, From Novice to Professional


We will also give away two copies of Beginning C++17, From Novice to Professional.

The event is free for everyone, but you need to register for it.

There are 50 seats available for this event.

Note: The deadline for registrations is June 30th, 2019!

Share

Chinese Translation of Professional C++ 4th Edition

I’m happy to announce that the number 1 university in China, the Tsinghua University, has finished with the translation work for my book “Professional C++ 4th Edition“.

The Chinese version can be found here.

Share

Visual Studio 2019 Released

On 2nd of April, Microsoft has released Visual Studio 2019. It comes with a host of IDE and performance improvements. For C++ developers, here are some new features:

  • Save time when writing C++ and XAML code by using Visual Studio IntelliCode, an optional extension that gives AI-assisted recommendations for your code.
  • Experience in-editor code analysis warnings. Code analysis runs automatically in the background and warnings display as green squiggles.
  • Try the new Template Bar, which uses the Peek Window UI and supports nested templates.
  • Run the new, updated implementation of the C++ Lifetime profile checker.
  • Configure your CMake projects using the new CMake Settings Editor, which provides an alternative to CMakeSettings.json.
  • Try out a host of backend improvements including OpenMP SIMD vectorization, link-time speedups, and more aggressive inlining.
  • Open existing CMake caches generated by external tools, such as CMakeGUI, or customized meta-build systems.
  • Improve analysis with /Qspectre for providing mitigation assistance for Spectre Variant 1 (CVE-2017-5753). For more information, see the Visual C++ Team Blog post.
  • Quickly switch between your previous sample arguments now that the Template Bar for Template IntelliSense has a Most Recently Used dropdown.

This is just a selection of some of the new features. The new release includes other productivity, CMake-related, and backend improvements for C++. The full release notes can be found here.

Share

Visual Studio 2019 Preview 2 Improvements

The recently released Preview 2 of Microsoft Visual Studio 2019 contains quite a few improvements and new features.

Lifetime Profile Checker

Preview 2 includes a Lifetime Profile Checker that implements the Lifetime Profile as published by the C++ Core Guidelines. It includes:

  • Support for iterators, string_views, and spans.
  • Better detection of custom Owner and Pointer types which allows custom types that behave like Containers, Owning-Pointers, or Non-Owning Pointers to participate in the analysis.
  • Type-aware default rules for function call pre and post conditions help reduce false-positives and improve accuracy.
  • Better support for aggregate types.
  • General correctness and performance improvements.
  • Some simple nullptr analysis.

This feature is not enabled by default, but you can enable it in the code analysis ruleset for your project. An example of what this checker can catch is the following in which we have a dangling string_view:

std::string get_string();
void dangling_string_view()
{
    std::string_view sv = get_string();
    auto c = sv.at(0);
}

You can read more about this feature here.

Backend Updates: New Optimizations, OpenMP, and Build Throughput improvements

New features include:

  • Added a new inlining command line switch: -Ob3. -Ob3 is a more aggressive version of -Ob2.
  • Added basic support for OpenMP SIMD vectorization.
  • Added a new C++ exception handler __CxxFrameHandler4 that reduces exception handling metadata overhead by 66%.
  • Support for Short Vector Math Library (SVML) intrinsic functions.

New and improved optimizations include:

  • Useless struct/class copies are being removed in several more cases, including copies to output parameters and functions returning an object. This optimization is especially effective in C++ programs that pass objects by value.
  • Unrolled memsets and block initializations will now use SSE2 instructions (or AVX instructions if allowed).
  • The compiler recognizes memmove() as an intrinsic function and optimizes accordingly.
  • Several new scalar fused multiply-add (FMA) patterns are identified with /arch:AVX2 /fp:fast.

Preview 2 also improves build throughput. Link times might be improved up to 2x.

The new linker will now report potentially matched symbol(s) for unresolved symbols, like:

main.obj : error LNK2019: unresolved external symbol _foo referenced in function _main
  Hint on symbols that are defined and could potentially match:
    "int __cdecl foo(int)" (?foo@@YAHH@Z)
    "bool __cdecl foo(double)" (?foo@@YA_NN@Z)
    @foo@0
    foo@@4
main.exe : fatal error LNK1120: 1 unresolved externals

More details can be found on this blog post.

Template IntelliSense Improvements

The following updates for Template IntelliSense are included with Preview 2:

  • Peek Window UI
  • Live Edits
  • Nested Template support
  • Default Argument watermarks

Read all about it on this blog post.

C++ Productivity Improvements

Preview 2 comes with the following new quick fixes and code navigation improvements:

  • Quick fixes for:
    • Add missing #include
    • NULL to nullptr
    • Add missing semicolon
    • Resolve missing namespace or scope
    • Replace bad indirection operands (* to & and & to *)
  • Quick Info on closing brace
  • Peek Header / Code File
  • Go to Document on #include

Read more about this new features here.

New Code Analysis Checks

Preview 2 includes new code analysis checks:

  • Use-after-move checker
  • Coroutine related checkers

Read more about them here.

In-editor Code Analysis Improvements

Code analysis now runs automatically in the background, and warnings display as green squiggles in-editor. Analysis re-runs every time you open a file in the editor and when you save your changes.

Squiggles are improved. Squiggles are now only displayed underneath the code segment that is relevant to the warning.

Read more here.

Share

Presentation: Modern C++ – Memory Management

A while ago, I gave a presentation about memory management in modern C++. It touched the following topics:

  • Real Null Pointer Type
  • Things To Unlearn
  • Pointers
  • Old C++ Versus New C++
  • Avoid delete
  • Automatic Lifetime (stack & heap)
  • RAII
  • Garbage Collection in C++?

Below you can find the slides of that presentation.

Share

C++17: std::scoped_lock

C++17 includes an std::scoped_lock (defined in <mutex>) which basically replaces std::lock_guard. Both are RAII classes that automatically unlock a mutex when they are destroyed. The only difference between the two is that the new scoped_lock can handle multiple mutexes automatically, while lock_guard is limited to a single mutex.

Using the scoped_lock RAII class is straightforward. Here is an example:

std::mutex mutex1;
// ...
std::scoped_lock<std::mutex> sl(mutex1);

The scoped_lock class template is a variadic template supporting any number of mutexes:

std::mutex mutex1;
std::recursive_mutex mutex2;
// ...
std::scoped_lock<std::mutex, std::recursive_mutex> sl(mutex1, mutex2);

The declaration of the scoped_lock can be simplified thanks to C++17 template argument deduction for constructors:

std::mutex mutex1;
std::recursive_mutex mutex2;
// ...
std::scoped_lock sl(mutex1, mutex2);


Share

C++17: Template Argument Deduction for Constructors

C++ always had support for template argument deduction when calling function templates. For example, suppose you have the following function template:

template<typename T>
void MyFunction(const T& data) { /* ... */}

It’s a function template with one template parameter. When you call this function, you do not have to specify the type of the template parameter explicitly. C++ automatically deduces the type T based on the arguments passed to the function. For example:

MyFunction(5);
MyFunction("Test");

If you really want to specify the template type explicitly you do this as follows:

MyFunction<int>(5);
MyFunction<std::string>("Test");

Up to C++17, this deduction only worked for function templates. C++17 adds support for template argument deduction for constructors of class templates.

For example, before template argument deduction for constructors, when you instantiate any Standard Library container you have to specify the type of the elements you want to store in the container:

std::vector<int> ints = { 11,22,33 };

With C++17’s template argument deduction for constructors, you can omit the explicit specification of the type. Of course, this only works when you instantiate the container and immediately initialize it with initial elements, otherwise the compiler has no data from which it can deduce any types. So, the above example can be written in C++17 as follows:

std::vector ints = { 11,22,33 };

This seemingly little feature has quite an impact. Because of the lack of this feature in previous versions of C++, the Standard Library included helper function templates. For example, a std::pair<int, std::string> can be constructed in the following two ways (pre-C++17):

std::pair<int, std::string> myPair1{ 11, "Eleven" };
auto myPair2 = std::make_pair(12, "Twelve");

Either you directly use the std::pair class and explicitly specify the template parameters, or, you use the specially-introduced std::make_pair() function template that can do the template argument deduction.

With C++17’s new deduction rules, you can forget about the helper function templates, and simply write the following:

std::pair myPair3{ 13, "Thirteen" };

Similarly for other helper function templates that were introduced earlier like std::make_move_iterator() to make a std::move_iterator(), and so on.

If you want to add support for template argument deduction to your own classes, then you will have to write your own so-called deduction guides, but that’s for a future post.

Share

Next BeCPP UG Meeting Planned For February 4th, 2019

The next meeting of the Belgian C++ Users Group is planned for Monday February 4th, 2019 at 18:00 at Sioux @ Aldhem Hotel (Room d’Artagnan 3 & 4).

Sioux ( http://www.sioux.eu/ ) is sponsoring this event by providing the location, drinks and catering.

Sioux Logo

The agenda is as follows:

  • 18:00: Sandwiches.
  • 18:30: Session 1: Parsing CSS in C++ with Boost Spirit X3 (Ruben Van Boxem)
    Reading and writing is a fundamental part of programming. Even more so in C++, as it is a relatively low-level language. If not hand-written from scratch, C++ programmers often resort to parser generators such as Antlr, Bison, byacc, Flex, and many others. The former option increases maintenance burden, as the code involved is usually not trivial and error-prone. The latter option complicates the build setup and one loses a certain degree of flexibility in how the parser can be handled.
    The authors of Boost.Spirit approached this dichotomy, shook it up a bit, and came up with something better. Boost Spirit, already at its third iteration of implementation, harnesses the C++ language and its generative power to enable us to write parser grammar in C++. This allows for the flexibility of using C++, combined with full control of what is parsed how, while maintaining the simplistic abstract representation of what is being parsed. The latest iteration, X3, employs techniques made possible by C++14 to simplify its implementation, to decrease compile times whilst providing the same flexibility of previous versions. I intend to give a general introduction, followed by a partial implementation of a CSS parser, and hope the power of Boost Spirit can convince you to at least give it whirl.
  • 19:30: Break
  • 19:45: Session 2: Using Monoids in C++ (Kristoffel Pirard)
    Effective coders recognise tedious repetition and transform it into reusable patterns. Frameworks, libraries and design patterns arise from it. After the GoF Object Oriented patterns, today we are also learning from the functional programming world. One of the patterns they bumped into is the Monoid: it has its application in addition, accumulation, concatenation, you name it. And it’s a simple one.
    This talk is about how Monoids seem to be everywhere, and how recognising them has influenced my daily practice. It will show a glimpse of the land of functional design patterns and look at practical aspects of using Monoids in C++. I believe it’s important. And I believe there’s a lot more to be discovered.
  • 20:45: Introduction to Sioux, followed by a drink.

Professional C++, 4th Edition
We will be giving away 2 copies of Professional C++, the 4th Edition.

C++ Standard Library Quick Reference
We will also be giving away a copy of C++ Standard Library Quick Reference.

Beginning C++17, From Novice to Professional
And finally, we will also give away a copy of Beginning C++17, From Novice to Professional.

The event is free for everyone, but you need to register for it.

There are 70 seats available for this event.

Note: The deadline for registrations is January 27th, 2019!

Share

Visual Studio 2017 version 15.9 Released

Microsoft has release version 15.9 of Visual Studio 2017. This update includes a few interesting new additions for C++ developers. From their VC++ release notes:

  • We’ve added the “step back” feature in the debugger for C++ in the Visual Studio Enterprise Edition. Step back enables you to go back in time to view the state of your application at a previous point in time.
  • C++ IntelliSense now responds to changes in the remote environment for both CMake and MSBuild projects targeting Linux. As you install new libraries or change your CMake projects, C++ IntelliSense will automatically parse the new headers files on the remote machine for a complete and seamless C++ editing experience.
  • We’ve updated the UWP Desktop Bridge framework packages to match the latest in the Windows Store for all supported architectures, including ARM64.
  • In addition to fixing 60 blocking bugs, we have added support for the range-v3 library with the MSVC 15.9 compiler, available under /std:c++17 /permissive-.
  • The retail VCLibs framework package in Visual Studio has been updated to match the latest available version in the UWP Store.
  • Full support is now available for ARM64 C++ Native Desktop scenarios, including VC++ 2017 Redistributable.
  • We implemented the shortest round-trip decimal overloads of floating-point to_chars() in C++17’s charconv header. For scientific notation, it is approximately 10x as fast as sprintf_s() “%.8e” for floats, and 30x as fast as sprintf_s() “%.16e” for doubles. This uses Ulf Adams’ new algorithm, Ryu.
  • A list of improvements to the standards conformance of the Visual C++ compiler, which potentially require source changes in strict conformance mode, can be found here.

You can find the full release notes here.

Share

Video of my CppCon 2018 Presentation “Writing Standard Library Compliant Data Structures and Algorithms”

On September 27th, 2018 I gave a presentation titled “Writing Standard Library Compliant Data Structures and Algorithms” at CppCon 2018.
You can find the slides here.

The official video is now also available on YouTube. Enjoy 🙂

Share

C++17: Standard Library Algorithms: Changes and Additions

The C++14 Standard Library already contains a wealth of different kinds of algorithms. C++17 adds the following new algorithms and new options to existing algorithms:

  • std::sample()
  • std::for_each_n()
  • Specialized searchers for std::search()
  • Generalized sum algorithms:
    • exclusive_scan()
    • inclusive_scan()
    • transform_exclusive_scan()
    • transform_inclusive_scan()
    • reduce()
    • transform_reduce()
  • Parallel algorithms
  • gcd() / lcm()

I wrote an article for the Visual C++ Team Blog explaining what’s new and what has changed related to algorithms in the C++17 Standard Library in more details.

You can read the article over here.

Share

Slides of my CppCon 2018 Presentation “Writing Standard Library Compliant Data Structures and Algorithms”

On September 27th, 2018 I gave a presentation titled “Writing Standard Library Compliant Data Structures and Algorithms” at CppCon 2018.
The slides of my presentation can be downloaded below:

Share

C/C++ Challenge by Dekimo


The Dekimo C/C++ Challenge is a contest designed to inspire creative and enthousiastic C/C++ Students & Professionals located in Belgium.

The first round is played online. The students and the professionals will compete in separate leagues so that everyone gets a fair chance in competing to be crowned as Belgian C/C++ Champion.

Registration is free and open during the entire duration of the Challenge (6 weeks, September 24 till November 2, 2018).

At the end of the online round, the top 20 players will be invited for the finals.

  • The 10 best Professionals
  • The 10 best Students

The finals will take place on Thursday, November 15, 2018 starting at 18:30 at the EDITx headquarters in Brussels (more details will follow).

The finals are intended to determine the top player in each league. Of course, there are cool prizes to be won that all have to do with smart electronics (a nifty drone for the winner in each league, and a nice voucher for the runners-up!)

Visit the official website for more details.

Share

Next BeCPP UG Meeting Planned For October 25th, 2018

The next meeting of the Belgian C++ Users Group is planned for Thursday October 25th, 2018 at 18:00 at Altran.

Altran ( http://www.altran.com/ ) is sponsoring this event by providing the location, drinks and catering.

Altran Logo

The agenda is as follows:

  • 18:00: Sandwiches.
  • 18:30: Session 1: Writing Standard Library Compliant Data Structures and Algorithms (Marc Gregoire)
    The C++ Standard Library provides a lot of data structures, but it cannot provide every possible data structure or algorithm that you might need. So, sometimes, you might find the need to write your own data structure or algorithm. Since you are writing them yourself, you could give them any interface that suits you. However, wouldn’t it be better to make them compliant with the Standard Library? That way, when you write your own algorithm, you will be able to use that algorithm independently of the type of the container that contains the data for your algorithm. Similarly, if you write a Standard Library compliant data structure, then you will be able to use Standard Library algorithms on the data in your own data structure.
    It’s clear, there are a lot of advantages in making your data structures and algorithms compliant with the Standard Library. We’ll first develop a simple algorithm with our own interface. Then we’ll look into what changes we have to make to transform the interface to be Standard Library compliant. Finally, we’ll demonstrate our adapted algorithm by running it on data in a variety of Standard Library containers.
    In the last part of the presentation we’ll crank it up a notch. We’ll start by writing our own data structure, initially without thinking too much about the Standard Library. Then we’ll look at an overview of the different sets of requirements that the Standard Library imposes for the different types of containers (sequential, associative, and unordered associative). Finally, we’ll adapt our data structure step-by-step to transform it into a Standard Library compliant data structure. This of course includes writing a suitable iterator. Finally, we’ll demonstrate the transformed data structure by running Standard Library algorithms on the data in it.
  • 19:30: Break
  • 19:45: Session 2: Memory Architecture & Performance (Barry Van Landeghem)
    The impact of memory architecture on performance is something which every developer should be aware of. In general improving your code performance is already hard and complex. Computer cache memories have led to introduce a new complexity measure for algorithms and new performance counters for code.
    In this talk we’ll see what data locality is all about and why using data locality can be a great tool for a developer to boost the performance of his/her algorithms/data structures.
    At the end we’ll also at the implications towards parallelism (false sharing/NUMA,…).
  • 20:45: Introduction to Altran, followed by a drink.

Professional C++, 4th Edition
We will be giving away 2 copies of Professional C++, the 4th Edition.

The event is free for everyone, but you need to register for it.

There are 80 seats available for this event.

Note: The deadline for registrations is October 21st, 2018!

Share

C++17 in Detail by Bartłomiej Filipek


C++17 provides developers with a nice selection of new features to write better, more expressive code.

Bartłomiej Filipek has released a book titled “C++17 in Detail” that describes all significant changes in the language and the Standard Library. What’s more, it provides a lot of practical examples so you can quickly apply the knowledge to your code. The book brings you exclusive content about C++17. Additionally, the book provides insight into the current implementation status, compiler support, performance issues and other relevant knowledge to boost your current projects.

The book is a work in progress and is currently 90% finished. The final version should be coming in at around 250 pages. Even though it’s not finished yet, if you buy early, you’ll get free updates later.

Here are the features you’ll learn from reading this book:

Part One: C++17 Language features

  • Fixes and deprecation
  • Language clarification
  • General language features
  • Templates
  • Attributes

Part Two: C++17 The Standard Library

  • std::optional
  • std::variant
  • std::any
  • std::string_view
  • String operations
  • Filesystem
  • Parallel STL
  • Other Changes

Part Three: More Examples and Use Cases

  • Refactoring with std::optional
  • Using if constexpr
  • … and more planned

You can find more information on the book’s website.

Share