November 2018

CppCast Episode 177: BDD, TDD, Low Latency and CppCon with Lenny Maiorani

Episode 177 of CppCast the first podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Lenny Maiorani to discuss TDD, BDD, Low Latency and CppCon moving to Denver.

CppCast Episode 177: BDD, TDD, Low Latency and CppCon with Lenny Maiorani

by Rob Irving and Jason Turner

About the interviewee:

Lenny has been using C++ off and on since 1995. Since graduating from SUNY Plattsburgh with a degree in Computer Science, he has been working at startups focused on high-throughput applications. About 2 years ago he joined Quantlab and discovered a different type of high-performance computing in low latency systems. Lenny lives in Denver, Colorado with his wife Lexey and their dog. He can be found hiking in the Colorado mountains while thinking about container access patterns and wondering if std::map can be renamed to std::ordered_map.

How to Design Function Parameters That Make Interfaces Easier to Use (2/3)--Jonathan Boccara

Agree with the logic?

How to Design Function Parameters That Make Interfaces Easier to Use (2/3)

by Jonathan Boccara

From the article:

Let’s continue exploring how to design function parameters that help make both interfaces and their calling code more expressive.

If you missed on the previous episode of this topic, here is what this series of articles contains:

  • Part 1: interface-level parameters, one-parameter functions, const parameters,
  • Part 2: calling contexts, strong types, parameters order,
  • Part 3: packing parameters, processes, levels of abstraction.

How to Boost Performance with Intel Parallel STL and C++17 Parallel Algorithms--Bartlomiej Filipek

Another one.

How to Boost Performance with Intel Parallel STL and C++17 Parallel Algorithms

by Bartlomiej Filipek

From the article:

C++17 brings us parallel algorithms. However, there are not many implementations where you can use the new features. The situation is getting better and better, as we have the MSVC implementation and now Intel’s version will soon be available as the base for libstdc++ for GCC.

Since the library is important, I’ve decided to see how to use it and what it offers...

Python-Like enumerate() In C++17--Nathan Reed

Handy little piece of code.

Python-Like enumerate() In C++17

by Nathan Reed

From the article:

Python has a handy built-in function called enumerate(), which lets you iterate over an object (e.g. a list) and have access to both the index and the item in each iteration. You use it in a for loop, like this:

for i, thing in enumerate(listOfThings):
    print("The %dth thing is %s" % (i, thing))

Iterating over listOfThings directly would give you thing, but not i, and there are plenty of situations where you’d want both (looking up the index in another data structure, progress reports, error messages, generating output filenames, etc).

C++ range-based for loops work a lot like Python’s for loops. Can we implement an analogue of Python’s enumerate() in C++? We can!

AWS launches the C++ lambda runtime

aws.PNGMore C++ and the cloud:

Introducing the C++ Lambda Runtime

by Chris Munns

From the article:

Today, AWS Lambda announced the availability of the Runtime API. The Runtime API allows you to write your Lambda functions in any language, provided that you bundle it with your application artifact or as a Lambda layer that your application uses.

As an example of using this API and based on the customer demand, AWS is releasing a reference implementation of a C++ runtime for Lambda. This C++ runtime brings the simplicity and expressiveness of interpreted languages while maintaining the superiority of C++ performance and low memory footprint. These are benefits that align well with the event-driven, function-based, development model of Lambda applications...

Quick Q: Regarding shared_ptr reference count block

Quick A: it is an implementation detail for the std.

Recently on SO:

Regarding shared_ptr reference count block

(1) Regarding size: How can I programatically find the exact size of the control block for a std::shared_ptr?

There is no way. It's not directly accessible.

(2) Regarding logic: Additionally, boost::shared_ptr mentions that they are completely lock-free with respect to changes in the control block.(Starting with Boost release 1.33.0, shared_ptr uses a lock-free implementation on most common platforms.) I don't think std::shared_ptr follows the same - is this planned for any future C++ version? Doesn't this also mean that boost::shared_ptr is a better idea for multithreaded cases?

Absolutely not. Lock-free implementations are not always better than implementations that use locks. Having an additional constraint, at best, doesn't make the implementation worse but it cannot possibly make the implementation better.

Consider two equally competent programmers each doing their best to implement shared_ptr. One must produce a lock-free implementation. The other is completely free to use their best judgment. There is simply no way the one that must produce a lock-free implementation can produce a better implementation all other things being equal. At best, a lock-free implementation is best and they'll both produce one. At worse, on this platform a lock-free implementation has huge disadvantages and one implementer must use one. Yuck.

Meeting C++ and Meeting Embedded trip report--Conan C/C++ Package Manager

Were you there? 

Meeting C++ and Meeting Embedded trip report

by Conan C/C++ Package Manager

From the article:

On Wednesday, before Meeting C++, we attended and presented a talk at Meeting Embedded, a new conference about many topics related to embedded systems. C++ and C had a relevant role in this conference, obviously (accordingly to Dan Saks statistics around 60% in embedded code is C, then around 20% is C++, followed by assembly), but where other topics presented, like Rust, protocols for embedded (MQTT), academic and professional education, real-time systems.

We did our own talk Continuous Integration of C/C++ for embedded and IoT with Jenkins, Docker and Conan, which went quite well, especially considering that we were running a real demo, live updating the embedded code in a Raspberry PI, that was built with Docker in Jenkins, using cross-compiled (from Windows) packages, and uploaded to Artifactory, all of that done in the live demo...

Quick Q: What does it mean to return a reference?

Quick A: The returned variable can be modified.

Recently on SO:

What does it mean to return a reference?

It means you return by reference, which is, at least in this case, probably not desired. It basically means the returned value is an alias to whatever you returned from the function. Unless it's a persistent object it's illegal.

For example:

int& foo () {
    static int x = 0;
    return x;

int main()
    foo() = 2;
    cout << foo();

would be legal and print out 2, because foo() = 2 modifies the actual value returned by foo.


int& doit () {
    int x = 0;
    return x;

would be illegal (well, accessing the returned value would), because x is destroyed when the method exits, so you'd be left with a dangling reference.

Returning by reference isn't common for free functions, but it is for methods returning members. For example, in the std, the operator [] for common containers return by reference. For example, accessing a vector's elements with [i] returns an actual reference to that element, so v[i] = x actually changes that element.

Also, I hope that "is essentially equal to this code" means that they're semantically sort of (but not really) similar. Nothing more.