December 2016

Return early and clearly—Arne Mertz

How to return well:

Return early and clearly

by Arne Mertz

From the article:

There are different guidelines out there about where and how many return statements to use in a function, e.g. return only once at the end of the function or return early and often. Which one makes for the most readable code?

CppCast Episode 83: Regular Void with Matt Calabrese

Episode 83 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Matt Calabrese to talk about his Regular Void Proposal, template<auto>, the state of Concepts and more.

CppCast Episode 83: Regular Void with Matt Calabrese

by Rob Irving and Jason Turner

About the interviewee:

Matt Calabrese is a software engineer working primarily in C++. He started his programming career in the game industry and is now working on libraries at Google. Matt has been active in the Boost community for over a decade, is currently a member of the Boost Steering Committee, and is a member of the Program Committee for C++Now. Starting in the fall of 2015, he has been attending C++ Standards Committee meetings, authoring several proposals targeting the standard after C++17, notably including a proposal to turn the void type into an instantiable type and a proposal for the standard library to introduce a generic algorithm for invoking standard Callables with argument types and argument amounts that may be partially calculated at compile-time or at runtime. He is also the author of the controversial paper "Why I want Concepts, but why they should come later rather than sooner", which may have contributed to the decision to not include the concepts language feature in C++17.

Building a hybrid spin mutex in C++—Foster Brereton

Forster Brereton reports about his first steps to build a hybrid mutex.

Building a hybrid spin mutex in C++

by Foster Brereton

From the article

Blocking Mutexes
A blocking mutex will halt the thread until it acquisition. It is useful because it consumes negligible computer resources while blocked. This leaves the CPU free to perform other tasks, including whatever other task currently owns the mutex. All this goodness is not cheap, however: it takes a decent amount of time to block thread. If your critical section is brief, you could be spending a disproportionate amount of time protecting it instead of running it.
Generally, blocking mutexes should be used when your critical section will take a while, such as I/O operations, calling out to the OS, or doing laundry in a collegiate dorm.


Spinning Mutexes
A spinning mutex will enter into an infinite loop (spin) until acquisition. It is useful because it can resume very quickly once the lock has been obtained, resulting in minimal overhead while protecting a critical section. However, since the thread remains active on the CPU, it can reduce (or eliminate!) the ability of the CPU to do other work††. If your critical section is long, you could be spending a disproportionate amount of time protecting it instead of running it.
Generally, spin mutexes should be used when your critical section is brief, such as reading or writing a memory-resident data structure.

Finding a middle ground
The dichotomy between the two mutex behaviors has left me stuck more than once. What if I was trying to protect a global resource that occasionally required a call to the OS? In those cases a blocking mutex is not a good fit, as modifying the memory-resident structure is pretty quick. However a spin mutex would be equally bad, because I do need to go to the OS time and again, and it would be a pessimization to spike a CPU while doing so.

Quantifiers, metaprogramming and concepts—Nikos Athanasiou

Quantification expresses the extent to which a predicate is true over a set of elements. This installment describes the use of predicate logic in metaprogramming.

Quantifiers, metaprogramming and concepts

by Nikos Athanasiou

From the article:

Metaprograms often use predicate logic in creative ways. For example, type queries in generic code are used to constrain, dispatch, specialize, activate or deactivate code at compile time.

Flip, a new data model C++ framework focused on real time collaboration

Irisate has made available a demo package of Flip, a C++ Framework allowing for a fast, efficient and reliable implementation of concurrent editing by multiple users.

Flip, a new data model C++ framework focused on real time collaboration

by Gregory Makles

From the article:

Flip is a data model library designed as a framework. It is real-time, collaboration-oriented, transactional, portable, compact and can handle complex data structures.

Essential Features

  • Single author applications can be adapted to support simultaneous co-authoring with no extra work
  • Undo/Redo and history are automatically handled (no action classes)
  • Copy/Paste can be done automatically, or refined to your needs and your data structure
  • Allows for offline mode and three-ways merge
  • Multi-threaded/multi-process architecture
  • Transactional
  • Server side is limited to data model code, making it less prone to bugs
  • High stability
  • Performance oriented, extensible, and future-proof document formats
  • At the core of Ohm Studio's unrivaled collaboration solution
  • Designed for easy integration with all kind of data structure, including decade(s) old ones

Registration is necessary to download Flip.

Overload 136 is now available

ACCU’s Overload journal of December 2016 is out. It contains the following C++ related articles.

Overload 136 is now available

From the journal:

The MirAL Story
Description : The X-Windows system is all-pervasive but struggles with security and performance graphics. Alan Griffiths introduces Mir Abstraction Layer to deal with these issues. by Alan Griffiths

Overloading with Concepts
Description : Concepts can play a role in function overloading. Andrew Sutton shows us how. by Andrew Sutton

Ultra-fast Serialization of C++ Objects
Description : Serialising and de-serialising is a common problem. Sergey Ignatchenko and Dmytro Ivanchykhin demonstrate one way to do this quickly. by Sergey Ignatchenko and Dmytro Ivanchykhin

Modern C++ Features: User-Defined Literals
Description : User-defined literals were introduced in C++11. Arne Mertz walks us through their use. by Arne Mertz

Python Streams vs Unix Pipes
Description : Dealing with an infinite sequence requires some thought. Thomas Guest presents various ways to approach such a problem. by Thomas Guest

Letter
Description : Silas S. Brown comments on Steve Love's recent article. by Silas S. Brown

Hello World in Go
Description : Go provides a way to write efficient concurrent programs in a C-like language. Eleanor McHugh shares a "Hello, world!" tutorial. by Eleanor McHugh

More Meeting C++ 2016 videos are online!

A week full of video editing brings the first batch of Meeting C++ 2016 videos online:

More videos are online!

by Jens Weller

Meeting C++ 2016 Playlist

From the article:

With today, almost all videos from the A and all videos of the D Track are online. There is a recording issue with one talk in the A track, which might get resolved in 2017. Also since today, the Meeting C++ YouTube channel has more then 400k views!

The full video set you can find in the Meeting C++ 2016 Playlist, the newest videos are easily found by visiting the Meeting C++ YouTube channel or subscribing to this RSS feed.

CppCast Episode 82: Catch 2 and C++ the Community with Phil Nash

Episode 81 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Phil Nash, Developer Advocate at JetBrains, to talk about updates to the Catch Unit test library and new features coming to CLion and ReSharper for C++.

CppCast Episode 82: Catch 2 and C++ the Community with Phil Nash

by Rob Irving and Jason Turner

About the interviewee:

Phil started coding back in the early 80s, on 8-bit home computers: from the ZX-81 to the Commodore 64, in BASIC and assembler. He later moved on to PCs and C++ in the early 90s and, despite forays into other languages, keeps coming back to C++. His career has taken him through domains such as anti-virus, mobile, finance and developer tools - among others. He's the original author of the C++ test framework, Catch and is now Developer Advocate at JetBrains for CLion, AppCode and ReSharper C++. His hobbies include writing podcast bios and trolling the podcast hosts.

Path Exploration—Adi Shavit

A short stroll along filesystem::path.

Path Exploration

by Adi Shavit

From the article:

The “experimental” Filesystem TS has been with us for a few years living in the std::experiment namespace. With C++17 it will finally be merged into std.