March 2019

Quick Q: Pointer to class data member “::*”

Quick A: a pointer that lets you access the value of the member of an instance.

Recently on SO:

Pointer to class data member “::*”

It's a "pointer to member" - the following code illustrates its use:

#include <iostream>
using namespace std;

class Car
{
    public:
    int speed;
};

int main()
{
    int Car::*pSpeed = &Car::speed;

    Car c1;
    c1.speed = 1;       // direct access
    cout << "speed is " << c1.speed << endl;
    c1.*pSpeed = 2;     // access via pointer to member
    cout << "speed is " << c1.speed << endl;
    return 0;
}

As to why you would want to do that, well it gives you another level of indirection that can solve some tricky problems. But to be honest, I've never had to use them in my own code.

Edit: I can't think off-hand of a convincing use for pointers to member data. Pointer to member functions can be used in pluggable architectures, but once again producing an example in a small space defeats me. The following is my best (untested) try - an Apply function that would do some pre &post processing before applying a user-selected member function to an object:

void Apply( SomeClass * c, void (SomeClass::*func)() ) {
    // do hefty pre-call processing
    (c->*func)();  // call user specified function
    // do hefty post-call processing
}

The parentheses around c->*func are necessary because the ->* operator has lower precedence than the function call operator.

C++ Core Guidelines: Mixing C with C++--Rainer Grimm

Mixing C and C++ from the point of view of a C++ engineer.

C++ Core Guidelines: Mixing C with C++

by Rainer Grimm

From the article:

The chapter in the C++ core guidelines is called: C-style programming. Honestly, my first thought was to skip it, but after more thoughts I decided to write about it. My reason is twofold:

  1. This are the typical issues we have when dealing with legacy code.
  2. One reader wanted that I write more about the challenges of legacy code.

Understanding C++ Modules: Part 1: Hello Modules, and Module Units--Colby Pike

Complex, but useful!

Understanding C++ Modules: Part 1: Hello Modules, and Module Units

by Colby Pike

From the article:

My previous posts on modules have received a lot of attention. I’m happy that I’ve been able to kick-start a lot of conversation, but I’ve also seen that a large part of the community is still unclear on what modules actually are.

There is a lot of ground to cover. I can’t do it all in one sitting, and I doubt you’d want to read the entire thing in one go. I’ll be breaking this up, starting at the most high-level aspects and drilling down over time. I intend these posts will clarify and discuss what modules are, what they can do, and what they are intended to do, what they cannot do, and how they are used...

Lambdas: From C++11 to C++20, Part 2--Bartlomiej Filipek

The series continues!

Lambdas: From C++11 to C++20, Part 2

by Bartlomiej Filipek

From the article:

In the first part of the series we looked at lambdas from the perspective of C++03, C++11 and C++14. In that article, I described the motivation behind this powerful C++ feature, basic usage, syntax and improvements in each of the language standards. I also mentioned several corner cases.

Now it’s time to move into C++17 and look a bit into the future (very near future!): C++20...

STL Algorithms on Tuples--Jonathan Boccara

Do you need them?

STL Algorithms on Tuples

by Jonathan Boccara

From the article:

When you manipulate a collection of objects in C++–which is quite a common thing to do when programming in C++–STL algorithms are your loyal companions to perform operations with expressive code.

But the STL algorithms, shipped in the standard library with C++, only apply to collections that are filled at runtime, during the execution of a program (or in C++20, during the execution of constepxr code during compilation). This include the ubiquitous std::vector and std::map.

But STL algorithms don’t operate on std::tuples.

However, it could be useful to iterate over the elements of a tuple, at runtime, and perform transformations or extract information, like STL algorithms do. We will see in detail a situation where this is useful with the demux output iterator, in a future post.

Can we design algorithms that are do what STL algorithms do, but on the contents of std::tuples instead of std::vectors and std::maps?

It turns out we can.

C++Now 2019 Attendee Video

"There's really not a conference like this one"

Register now for C++Now 2019 at cppnow.org!

C++Now 2019 Attendee Video

by C++ Now attendees

About the video

This video was created by Vittorio Romeo, Lisa Lippincott, Zach Laine, Odin Holmes, Phil Nash, Anastasia Kazakova, Jens Weller, and more

 

Trip report: February 2019 ISO C++ committee meeting, Kona, Hawai’i--Timur Doumler

Another report.

Trip report: February 2019 ISO C++ committee meeting, Kona, Hawai’i

by Timur Doumler

From the article:

What better way to start my new blog than to publish a trip report from the most recent C++ committee meeting on the wonderful Big Island of Hawai’i?

If you are looking for an incredibly detailed report of everything that happened, please instead head to this report by Bryce and others, and also see Herb Sutter’s and cor3ntin’s reports. I won’t try to provide this breadth of coverage, and instead focus on a few areas that are particularly relevant for me and the community that I am proxying here:

  • Making C++ simpler, more uniform, and easier to teach;
  • Providing developers with better tools;
  • Improving support for low-latency and real-time(-ish) programming,
  • 2D Graphics, Audio, and other forms of I/O and human-machine interaction.

That being said, let’s start with the big news: we voted both Coroutines and Modules into C++20!