Little-known C++: function-try-block--Marius Bancila
Did you know?
Little-known C++: function-try-block
by Marius Bancila
From the article:
Function-try-block is a mechanism in C++ to establish an exception handler around the body of a function...
October 25, Pavia, Italy
November 6-8, Berlin, Germany
November 3-8, Kona, HI, USA
By Adrien Hamelin | Mar 19, 2019 11:34 AM | Tags: intermediate
Did you know?
Little-known C++: function-try-block
by Marius Bancila
From the article:
Function-try-block is a mechanism in C++ to establish an exception handler around the body of a function...
By Adrien Hamelin | Mar 18, 2019 10:50 AM | Tags: performance advanced
Your complier does magic.
A gentle introduction to jump threading optimizations
by Aldy Hernandez
From the article:
As part of the GCC developers‘ on-demand range work for GCC 10, I’ve been playing with improving the backward jump threader so it can thread paths that are range-dependent. This, in turn, had me looking at the jump threader, which is a part of the compiler I’ve been carefully avoiding for years. If, like me, you’re curious about compiler optimizations, but are jump-threading-agnostic, perhaps you’ll be interested in this short introduction...
By Adrien Hamelin | Mar 18, 2019 10:49 AM | Tags: c++17
Unifying the types.
Thanks for the memory (allocator)
by Glennan Carnie
From the article:
One of the design goals of Modern C++ is to find new – better, more effective – ways of doing things we could already do in C++. Some might argue this is one of the more frustrating aspects of Modern C++ – if it works, don’t fix it (alternatively: why use lightbulbs when we have perfectly good candles?!)
This time we’ll look at a new aspect of Modern C++: the Allocator model for dynamic containers. This is currently experimental, but has been accepted into C++20.
The Allocator model allows programmers to provide their own memory management strategy in place of their default library implementation. Although it is not specified by the C++ standard, many implementations use malloc/free.
Understanding this feature is important if you work on a high-integrity, or safety-critical, project where your project standards say ‘no’ to malloc...
By Adrien Hamelin | Mar 13, 2019 12:53 PM | Tags: advanced
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.
By Adrien Hamelin | Mar 13, 2019 12:39 PM | Tags: community
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:
- This are the typical issues we have when dealing with legacy code.
- One reader wanted that I write more about the challenges of legacy code.
By Adrien Hamelin | Mar 12, 2019 12:04 PM | Tags: experimental advanced
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...
By Adrien Hamelin | Mar 12, 2019 11:54 AM | Tags: experimental c++17
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...
By Adrien Hamelin | Mar 12, 2019 11:46 AM | Tags: stl c++17
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.
By Adrien Hamelin | Mar 6, 2019 01:23 PM | Tags: experimental community
Help make the future of C++ better!
CMake + GCC module proof-of-concept
From the article:
Hi all, CMake developer here. There's been a lot of noise and discussion of modules recently, particularly with respect to how build systems will deal with it. There has been build2 for quite a while, but it was also designed with modules in mind...
By Adrien Hamelin | Mar 5, 2019 01:21 PM | Tags: community
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!