September 2015

CppCast Episode 26: Effective C++ with Scott Meyers

Episode 26 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Scott Meyers to discuss the Effective C++ book series.

CppCast Episode 26: Effective C++ with Scott Meyers

by Rob Irving and Jason Turner

About the interviewee:

Scott Meyers has been working with C++ since 1988. He’s the author of Effective C++, More Effective C++, Effective STL, and his most recent book, Effective Modern C++. For 25 years, he’s delivered C++ training to clients worldwide. He once lectured about C++ on a brass-railed nightclub stage while the audience sat at cocktail tables.

CppCon 2015 Program Highlights, 12 of N

The CppCon 2015 conference program has been posted for the upcoming September conference. We’ve received requests that the program continue to be posted in “bite-sized” posts, a few sessions at a time, to make the 100+ sessions easier to absorb, so here is another set of talks. This series of posts will conclude once the entire conference program has been posted in this way.

 

C++, it is also a language that we like to discover and master always more.

The following interrelated CppCon 2015 talks tackle these issues and more (part 3).

In this post:

  • Generic Lambdas from Scratch
  • Large Scale C++ With Modules: What You Should Know
  • Shared_Future from Scratch
  • Comparison is not simple, but it can be simpler
  • The Importance of Being const
  • Intro to the C++ Object Model

 

Generic Lambdas from Scratch by Arthur O'Dwyer, software engineer, Mixpanel

Lambdas (even those mysterious generic lambdas) are just syntactic sugar atop constructs that are perfectly understandable when approached from the right direction.

We'll start with the implementation of C-style functions, then move to overloading, function templates, non-static member functions, C++11 lambdas, and then demystify C++14 generic ("auto") lambdas. Finally, we'll detour into the implementations of std::function and std::bind to show how they're different from lambdas.


Large Scale C++ With Modules: What You Should Know by Gabriel Dos Reis, Principal Software Development Engineer, Microsoft

To be completed.


Shared_Future from Scratch by Arthur O'Dwyer, software engineer, Mixpanel

The contents of header are probably still a bit mysterious to most people. Sure, we know that setting the value of a promise causes the corresponding future to resolve; but how does that happen behind the scenes in a way that allows us to move futures around? How are we going to implement the new features in the Concurrency TS, such as .then() and .when_all()? How (if at all) do futures interact with std::thread, std::async, and "executors"?

We'll present an extremely simplified implementation of futures and shared_futures, without the template metaprogramming that comes along with future and future and so on, but showing all the pointers and synchronization primitives.


Comparison is not simple, but it can be simpler by Lawrence Crowl

The standard's algorithms typically require a 'strict weak ordering'. I will explain what this really means and show that even simple uses of sort can have latent failures. Programmers can avoid the problems today with a bit of work. Changes to the standard will reduce errors and programming effort.


The Importance of Being const by Richard Powell, Audio Software Engineer

Why do we use const? It helps the compiler enforce program invariants, find trivial bugs, and generally makes code better. But with C++11 has an extended meaning, specifically in regards to multi-threaded code.

This talk will be an intro to the const keyword and what it means to declare objects, pointers and member functions as const. We will also explore some subtle issues encountered with const, mutable, and multithreaded code.


Intro to the C++ Object Model by Richard Powell, Audio Software Engineer

This talk is to help you learn about how objects are represented in C++. I find it very helpful to have a mental model of how objects exist in the program memory space to understand how my code operates within program execution.

CppCon 2015 Program Highlights, 11 of N

The CppCon 2015 conference program has been posted for the upcoming September conference. We’ve received requests that the program continue to be posted in “bite-sized” posts, a few sessions at a time, to make the 100+ sessions easier to absorb, so here is another set of talks. This series of posts will conclude once the entire conference program has been posted in this way.

 

C++, it is also a language that we like to discover and master always more.

The following interrelated CppCon 2015 talks tackle these issues and more (part 2).

In this post:

  • Concurrency TS: The Editor's Report
  • `for_each_argument` explained and expanded
  • std::allocator Is to Allocation what std::vector Is to Vexation
  • <functional>: What's New, And Proper Usage
  • Type Traits - what are they and why should I use them?

 

Concurrency TS: The Editor's Report by Artur Laksberg, Software Engineer, Microsoft

In this presentation we will talk about the new C++ concurrency features that have been included in the Concurrency Technical Specification.

The TS should be of interest to anyone writing concurrent code in C++. The proposal includes improved futures for wait-free composition of asynchronous operations (including their relationship with C++ 'await'), new synchronization constructs as well as atomic smart pointers.


`for_each_argument` explained and expanded by Vittorio Romeo

During January 2015, Sean Parent posted a very interesting short piece of code on Twitter. The code iteratively iterates at compile-time over any number of function arguments, forwarding them one by one to a callable object.

How does this code work? What are the possible use cases? Can we make it even more generic and useful?

My talk answers all of the questions above, using independently compiled chronologically sequential code segments that show the audience the analysis and improvement process of `for_each_argument`.


std::allocator Is to Allocation what std::vector Is to Vexation by Andrei Alexandrescu, Founder, D Language Foundation

std::allocator has an inglorious past, murky present, and cheerless future. STL introduced allocators as a stop gap for the now antiquated segmented memory models of the 1990s. Their design was limited and in many ways wasn't even aiming at helping allocation that much. Because allocators were there, they simply continued being there, up to the point they became impossible to either uproot or make work, in spite of valiant effort spent by the community.

But this talk aims at spending less time on poking criticism at std::allocator and more on actually defining allocator APIs that work.

Scalable, high-performance memory allocation is a topic of increasing importance in today's demanding applications. For such, std::allocator simply doesn't work. This talk discusses the full design of a memory allocator created from first principles. It is generic, componentized, and composable for supporting application-specific allocation patterns.


<functional>: What's New, And Proper Usage by Stephan T. Lavavej, Senior Software Engineer, Microsoft

<functional> gained lots of machinery in C++11, with further changes in C++14 and C++17. This talk will cover what's new in 11/14/17, focusing on how to use it properly. For example, you've probably used std::function, but do you know the criteria for activating the Small Functor Optimization? (It's not just being small!) We'll also look at bind(), mem_fn(), C++17's invoke(), and more.


Type Traits - what are they and why should I use them? by Marshall Clow, Qualcomm

In this talk, I will answer the questions, "What are type traits?" and "Why are type traits useful?", along with some examples of why when when they should be used.

CppCon 2015 Program Highlights, 10 of N

The CppCon 2015 conference program has been posted for the upcoming September conference. We’ve received requests that the program continue to be posted in “bite-sized” posts, a few sessions at a time, to make the 100+ sessions easier to absorb, so here is another set of talks. This series of posts will conclude once the entire conference program has been posted in this way.

 

C++, it is also a language that we like to discover and master always more.

The following interrelated CppCon 2015 talks tackle these issues and more (part 1).

In this post:

  • Tuning C++: Benchmarks, and Compilers, and CPUs! Oh My!
  • Value Semantics: It ain't about the syntax!, Part I and Part II
  • Five amazing things you couldn't imagine C++ can do
  • C++ Atomics: The Sad Story of memory_order_consume: A Happy Ending at Last?
  • A C++14 approach to dates and times

 

Tuning C++: Benchmarks, and Compilers, and CPUs! Oh My! by Chandler Carruth, C++ Language and Compiler Lead, Google

A primary use case for C++ is low latency, low overhead, high performance code. But C++ does not give you these things for free, it gives you the tools to control these things and achieve them where needed. How do you realize this potential of the language? How do you tune your C++ code and achieve the necessary performance metrics?

This talk will walk through the process of tuning C++ code from benchmarking to performance analysis. It will focus on small scale performance problems ranging from loop kernels to data structures and algorithms. It will show you how to write benchmarks that effectively measure different aspects of performance even in the face of advanced compiler optimizations and bedeviling modern CPUs. It will also show how to analyze the performance of your benchmark, understand its behavior as well as the CPUs behavior, and use a wide array of tools available to isolate and pinpoint performance problems. The tools and some processor details will be Linux and x86 specific, but the techniques and concepts should be broadly applicable.


Value Semantics: It ain't about the syntax!, Part I and Part II by John Lakos, Software Infrastructure Manager, Bloomberg LP

When people talk about a type as having *value* *semantics*, they are often thinking about its ability to be passed to (or returned from) a function by value. In order to do that, the C++ language requires that the type implement a copy constructor, and so people routinely implement copy constructors on their classes, which begs the question, "Should an object of that type be copyable at all?" If so, what should be true about the copy? Should it have the same state as the original object? Same behavior? What does copying an object mean?! By *value* *type*, most people assume that the type is specifically intended to represent a member of some set (of values). A *value-semantic* *type*, however, is one that strives to approximate an abstract *mathematical* type (e.g., integer, character set, complex-number sequence), which comprises operations as well as values. When we copy an object of a value-semantic type, the new object might not have the same state, or even the same behavior as the original object; for proper value-semantic types, however, the new object will have the same *value*. In this talk, we begin by gaining an intuitive feel for what we mean by *value* by identifying *salient* *attributes*, i.e., those that contribute to value, and by contrasting types whose objects naturally represent values with those that don't. After quickly reviewing the syntactic properties common to typical value types, we dive into the much deeper issues that *value* *semantics* entail. In particular, we explore the subtle *Essential* *Property* *of* *Value*, which applies to every *salient* mutating operation on a value-semantic object, and then profitably apply this property to realize a correct design for each of a variety of increasingly interesting (value-semantic) classes.


Five amazing things you couldn't imagine C++ can do by Sasha Goldshtein

Modern C++ is incredibly flexible. It's truly the multi-paradigm language Bjarne Stroustrup envisioned. In this talk, we will explore five functions or small libraries that make use of modern C++'s amazing features. Among them: compile-time- and runtime-safe printf, automatic recursive serialization of containers, a simple but complete parallelism framework using only portable C++, and two others to keep you motivated.


C++ Atomics: The Sad Story of memory_order_consume: A Happy Ending at Last? by Paul McKenney, Distinguished Engineer, IBM Linux Technology Center

One of the big advantages of C++ atomics is that developers can now let the compiler know about the intent behind their multi-threaded synchronization mechanisms. At least they can tell the compiler as long as the synchronization mechanism in question is not RCU. You see, all production compilers promote RCU's memory_order_consume to memory_order_acquire. Although this promotion does ensure correctness, it also ensures the additional overhead of memory-barrier instructions on weakly ordered systems and of needlessly suppressed compiler optimizations on all systems.

All previous attempts to resolve this issue have foundered on either standard-committee reluctance to eviscerate the standard for a special case, compiler-writer reluctance to eviscerate their compilers for a special case, and kernel-developers reluctance to eviscerate their source base for late-to-the-party compiler support.

But now there is a glimmer of hope in the guise of a small set of small patches to the Linux kernel that eliminate the most challenging use cases. Will this hope be realized? Come to this talk to here the story, which by September will hopefully have a happy ending!


A C++14 approach to dates and times by Howard Hinnant, Senior Software Engineer, Ripple Labs

A new date and date/time library designed for C++14 is presented. This library stresses ease of use, easy-to-read code, catching common errors at compile time, and uncompromising run-time performance.

The design starts with the C++11 std::chrono library, and extends it into the realm of calendars, giving a seamless experience built upon chrono::system_clock::time_point, the durations you already know such as chrono::hours and nanoseconds. Functionality that allows easy and efficient conversions between the std::chrono types and year/month/day - hh::mm::ss data structures is presented.

When dates (and times) are known at compile-time (e.g. leap second transitions), all computations are available at compile time (constexpr). When only parts of a date are known at compile time, run-time efficiencies are still gained by compile-time computing parts of the date.

The syntax of the library is built around a few easy-to-learn rules, and strictly checked at compile time. This makes it easy to learn, and very forgiving for the novice.

A third way to use boost::serialization

The 10th installment in my series about writing applications with Qt and boost:

A third way to use boost::serialization

by Jens Weller

From the article:

The 10th part of my series about writing applications with Qt and boost is about using boost::serialization. The last part was about how to create the basic structure for a project with boost::filesystem, and how to use boost::filesystem to index folders. But there is a lot of data that just isn't able to be represented as single files, how to store it?

Originally I planned to use a database, as I already have some code handling the SQL queries nicely for me and most of my other applications currently also use this to store their data. Thats why most of my classes from the first day on had an id field, just to enable them to refer to an instance stored in a database. But then, if I could get around using a database, by simply just storing my data in a file, things would be easier, and my code wouldn't need to be scattered with SQL queries. If I couldn't find a reasonable approach, I still could opt for a database anyways.

CppCast Episode 25: Software Transactional Memory with Brett Hall

Episode 25 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Brett Hall to discuss Software Transactional Memory.

CppCast Episode 25: Software Transactional Memory with Brett Hall

by Rob Irving and Jason Turner

About the interviewee:

Brett Hall is the lead engineer on Dynamics, a desktop application that collects and analyzes data from the light scattering instruments built by Wyatt technology. Prior to joining Wyatt, Brett worked in web application development, remote sensing, and spent a summer in the games industry. He holds a PhD in physics from the University of California, Santa Barbara. Part of his research work involved using C++ to solve the PDE systems generated by the rest of the research. All told he’s been using C++ for around 20 years now. These days the bulk of his programming interest is in concurrency and parallelism. When not programming he’s usually hanging out with his family and/or mountain biking.