community

Trip Report: C++ Standards Meeting in San Diego, November 2018--Botond Ballo

New trip report.

Trip Report: C++ Standards Meeting in San Diego, November 2018

by Botond Ballo

From the article:

A few weeks ago I attended a meeting of the ISO C++ Standards Committee (also known as WG21) in San Diego, California. This was the third committee meeting in 2018; you can find my reports on preceding meetings here (June 2018, Rapperswil) and here (March 2018, Jacksonville), and earlier ones linked from those. These reports, particularly the Rapperswil one, provide useful context for this post...

Exploring Clang Tooling – Using Build Tools with clang-tidy--Stephen Kelly

Today about clang-tidy.

Exploring Clang Tooling – Using Build Tools with clang-tidy

by Stephen Kelly

From the article:

The previous series about clang-tidy on this blog covered the basics of creating a clang-tidy extension and tooling to support that in the form of clang-query.

While the series focused on single-file examples for simplicity, developers progressing in this direction will need to run the tooling on all of the files in their project at once, or on all files which match a specific pattern.

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.

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!

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...

How to teach C++--Marius Elvert

Do you have a way?

How to teach C++

by Marius Elvert

From the article:

In the closing Keynote of this year’s Meeting C++, Nicolai Josuttis remarked how hard it can be to teach C++ with its ever expanding complexity. His example was teaching rookies about initialization in C++, i.e. whether to use assignment =, parens () or curly braces {}. He also asked for more application-level programmers to participate.

Well, I am an application programmer, and I also have experience with teaching C++. Last year I held a C++ introductory course for experienced C programmers who mostly had never used C++ before. From my experience, I can completely agree with what Nico had to say about teaching C++. The language and its subtlety can be truly overwhelming.

Most of the complexity in C++ boils down to tuning your code for optimal performance. We cannot just leave that out, can we? After all, the sole reason to use C++ is performance, right?

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

Readability is important.

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

by Jonathan Boccara

From the article:

When you look at an function in an interface, 3 prominent things give you indications about how to use it: its name, its parameters and its return type. And when you look at a piece of code calling that function, it’s just its name and its function parameters.

We’ve already covered in details how to give good names to the components of your code. Now we’re going to examine how to design function parameters in a way that both your interfaces and the code that calls them are as expressive as can be.

Summed up in one sentence, you want to make the decision of what arguments to pass to your functions a no-brainer.

There are a lot of things to say about how to achieve this. So much so that you will find the contents broken down into 3 articles in order to make it easier to digest:

  • 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.

To support this series I’ve taken many examples from interfaces I’ve worked on, except that I’ve stripped out all domain aspects to make them both simpler and disclosable...