November 2020

Create a new type when using std::variant -- Zhihao Yuan

Enough typedefs.

Create a new type when using std::variant

by Zhihao Yuan

From the article:

class rock {};
class paper {};
class scissors {};
using hand = std::variant<rock, paper, scissors>;

Ignoring the fact that this hand type comes with heavily overloaded constructors and you can only add free functions, a troublesome issue is that the type-name std::variant<rock, paper, scissors> will appear everywhere in debuggers and linkers in place of hand.

Conditionally Trivial Special Member Functions--Sy Brand

c++ magic.

Conditionally Trivial Special Member Functions

by Sy Brand

From the article:

The C++ standards committee is currently focusing on adding features to the language which can simplify code. One small example of this in C++20 is conditionally trivial special member functions, which we added support for in Visual Studio 2019 version 16.8. Its benefit isn’t immediately obvious unless you’ve been deep down the rabbit hole of high-performance library authoring, so I’ve written this post to show you how it can make certain generic types more efficient without requiring huge amounts of template magic...

How to Share Code with Const and Non-Const Functions in C++--Bartlomiej Filipek

How do you do it?

How to Share Code with Const and Non-Const Functions in C++

by Bartlomiej Filipek

From the article:

During the development of a container-like type, I run into the problem of how to share code between a const and non-const member functions. In this article, I’d like to explain what are the issues and possible solutions. We can even go on a bleeding edge and apply some C++20 features. Which technique is most friendly?

2020-11 mailing available

The 2020-11 mailing of new standards papers is now available.

 

WG21 Number Title Author Document Date Mailing Date Previous Version Subgroup
N4869 WG21 Pre-Autumn 2020 telecon minutes Nina Ranns 2020-11-05 2020-11   All of WG21
N4870 WG21 2020-02 Prague Minutes of Meeting Nina Ranns 2020-11-09 2020-11   All of WG21
N4871 WG21 Pre-Autumn 2020 telecon minutes Nina Ranns 2020-11-09 2020-11   All of WG21
N4873 Working Draft, C++ Extensions for Library Fundamentals, Version 3 Thomas Köppe 2020-11-09 2020-11   All of WG21
N4874 Editor's Report: C++ Extensions for Library Fundamentals, Version 3 Thomas Köppe 2020-11-09 2020-11   All of WG21
N4875 WG21 admin telecon meeting: Winter 2021 Herb Sutter 2020-11-14 2020-11   All of WG21
N4876 WG21 virtual meeting: Winter 2021 Herb Sutter 2020-11-14 2020-11   All of WG21
N4877 WG21 2020-11 Virtual Meeting Minutes of Meeting Nina Ranns 2020-11-19 2020-11   All of WG21
P0401R4 Providing size feedback in the Allocator interface Chris Kennelly 2020-11-14 2020-11 P0401R3 LWG Library
P0447R11 Introduction of std::colony to the standard library Matt Bentley 2020-11-06 2020-11 P0447R10 SG14 Low Latency,LEWG Library Evolution,All of WG21
P0849R5 auto(x): decay-copy in the language Zhihao Yuan 2020-11-11 2020-11 P0849R4 EWG Evolution
P0901R7 Size feedback in operator new Chris Kennelly 2020-11-13 2020-11 P0901R6 CWG Core
P0943R6 Support C atomics in C++ Hans Boehm 2020-11-14 2020-11 P0943R5 All of WG21
P1012R1 Ternary Right Fold Expression Frank Zingsheim 2020-11-22 2020-11 P1012R0 EWG Evolution
P1018R7 C++ Language Evolution status �� pandemic edition �� 2020/03–2020/10 JF Bastien 2020-10-30 2020-11 P1018R6 EWG Evolution,All of WG21
P1102R1 Down with ()! Alex Christensen 2020-11-20 2020-11 P1102R0 CWG Core
P1206R3 ranges::to: A function to convert any range to a container Corentin Jabot 2020-11-22 2020-11 P1206R2 LEWG Library Evolution
P1478R5 Byte-wise atomic memcpy Hans Boehm 2020-11-14 2020-11 P1478R4 LEWG Library Evolution
P1787R6 Declarations and where to find them S. Davis Herring 2020-10-28 2020-11 P1787R5 CWG Core
P1885R4 Naming Text Encodings to Demystify Them Corentin Jabot 2020-11-22 2020-11 P1885R3 SG16 Unicode,LEWG Library Evolution
P1950R1 An indirect value-type for C++ Jonathan Coe 2020-11-22 2020-11 P1950R0 LEWG Library Evolution
P2012R0 Fix the range-based for loop, Rev0ix the range-based for loop Nicolai Josuttis 2020-11-15 2020-11   EWG Evolution,CWG Core
P2160R1 Locks lock lockables (wording for LWG 2363) Tim Song 2020-11-14 2020-11 P2160R0 LWG Library
P2164R3 views::enumerate Corentin Jabot 2020-11-22 2020-11 P2164R2 LEWG Library Evolution
P2181R1 Correcting the Design of Bulk Execution Jared Hoberock 2020-11-13 2020-11 P2181R0 SG1 Concurrency and Parallelism
P2182R1 Contract Support: Defining the Minimum Viable Feature Set Andrzej Krzemieński 2020-11-16 2020-11 P2182R0 SG21 Contracts
P2211R0 Exhaustiveness Checking for Pattern Matching David Sankel 2020-11-16 2020-11   EWG Evolution
P2212R2 Relax Requirements for time_point::clock Alexey Dmitriev 2020-11-12 2020-11 P2212R1 LEWG Library Evolution,LWG Library
P2233R1 2020 Fall Library Evolution Polls Bryce Adelstein Lelbach 2020-10-22 2020-11 P2233R0 LEWG Library Evolution
P2233R2 2020 Fall Library Evolution Polls Bryce Adelstein Lelbach 2020-10-22 2020-11 P2233R1 LEWG Library Evolution
P2242R0 Non-literal variables (and labels and gotos) in constexpr functions Ville Voutilainen 2020-10-21 2020-11   EWG Evolution,CWG Core
P2246R0 Character encoding of diagnostic text Aaron Ballman 2020-10-26 2020-11   SG16 Unicode,EWG Evolution
P2247R0 2020 Library Evolution Report Bryce Adelstein Lelbach 2020-11-03 2020-11   LEWG Library Evolution
P2248R0 Enabling list-initialization for algorithms Giuseppe D'Angelo 2020-11-01 2020-11   LEWGI SG18: LEWG Incubator
P2250R0 Scheduler vs Executor Ruslan Arutyunyan 2020-11-04 2020-11   SG1 Concurrency and Parallelism,LEWG Library Evolution
P2251R0 Require span & basic_string_view to be Trivially Copyable Nevin Liber 2020-11-08 2020-11   LEWGI SG18: LEWG Incubator
P2253R0 SG16: Unicode meeting summaries 2020-09-09 through 2020-11-11 Tom Honermann 2020-11-15 2020-11   SG16 Unicode
P2254R0 Executors Beyond Invocables Jared Hoberock 2020-11-15 2020-11   SG1 Concurrency and Parallelism,LEWG Library Evolution
P2255R0 A type trait to detect reference binding to temporary Tim Song 2020-11-14 2020-11   EWG Evolution,LEWG Library Evolution
P2257R0 Blocking is an insufficient description for senders and receivers Dalton M. Woodard 2020-11-22 2020-11   LEWG Library Evolution
P2259R0 Repairing input range adaptors and counted_iterator Tim Song 2020-11-19 2020-11   LWG Library
P2260R0 WG21 2020-11 Virtual Meeting Record of Discussion Nina Ranns 2020-11-19 2020-11   All of WG21

Why PVS-Studio Doesn't Offer Automatic Fixes

Static analyzer PVS-Studio can detect bugs in pretty complex and intricate parts of code, and coming up with appropriate fixes for such bugs may be a tough task even for human developers. That's exactly the reason why we should avoid offering any options for automatic fixing at all. Here are a couple of examples.

Why PVS-Studio Doesn't Offer Automatic Fixes

by Andrey Karpov

From the article:

But it only simplifies the code, not fixes it! Somebody else noticed this and opened a discussion: os_thread_windows.c - get_rel_wait() will block if abstime is in the past. As you can see, even humans make mistakes when trying to come up with a fix. Machines are just hopeless in that respect.

Overload 159 is now available

ACCU’s Overload journal of October 2020 is out. It contains the following C++ related articles.

Overload 159 is now available

From the journal:

Virtual/Reality
By Frances Buontempo
Do we know what reality is? Frances Buontempo is no longer sure and now wonders if she’s a fictional character.

poly::vector – A Vector for Polymorphic Objects
By Ferenc Nándor Janky
Heterogeneous vectors can be slow. Janky Ferenc introduces a sequential container for storing polymorphic objects in C++.

Kafka Acks Explained
By Slanislav Kozlovski
Kafka’s configuration can be confusing. Slanislav Kozlovski helps us visualise this most misunderstood configuration setting.

Concurrency Design Patterns
By Lucian Tadu Teodorescu
Orchestrating concurrent tasks using mutexes is seldom efficient. Lucian Tadu Teodorescu investigates design patterns that help unlock concurrent performance.

C++ Modules: A Brief Tour
By Nathan Sidwell
C++20’s long awaited module system has arrived. Nathan Sidwell presents a tourist’s guide.

The Edge of C++
By Ferenc Deák
Everything has limits. Deák Ferenc explores the bounds of various C++ constructs.

Afterwood
By Chris Oldwood
Assume failure by default. Chris Oldwood considers various fail cases.

Quick Q: Why do I have to access template base class members through the this pointer?

Quick: in order to make x a dependent name, so that lookup is deferred until the template parameter is known

Recently on SO:

Why do I have to access template base class members through the this pointer?

If the classes below were not templates I could simply have x in the derived class. However, with the code below, I have to use this->x. Why?

template <typename T>
class base {

protected:
    int x;
};

template <typename T>
class derived : public base<T> {

public:
    int f() { return this->x; }
};

int main() {
    derived<int> d;
    d.f();
    return 0;
}

Dependency Injection with Boost.DI -- Richard Thomson

Utah C++ Programmers has released a video on dependency injection with the Boost.DI library.

Dependency Injection with Boost.DI

by Richard Thomson

From the video description:

Richard Thomson gives us a presentation on dependency injection in C++.  We'll look at dependency injection in general and then look at dependency injection using the Boost.DI library.

YouTube: https://www.youtube.com/watch?v=zMTAc8WHIgo