Articles & Books

std::shared_ptr's secret constructor -- Anthony Williams

std::shared_ptr has a secret: the aliasing constructor, that most users don't even know exists, but which is surprisingly useful. 

std::shared_ptr's secret constructor

by Anthony Williams

From the article:

What does this secret constructor do for us? It allows us to construct a new shared_ptr instance that shares ownership with another shared_ptr, but which has a different pointer value...

 

 

boost::variant and a general, generic visitor class

Starting a new project with boost::variant, I got into thinking about a general generic visitor for boost::variant...

boost::variant and a general, generic visitor class

by Jens Weller

From the article:

So, I started a new project, and I do use boost::variant to be able to stick otherwise unrelated classes into the same container. Actually a tree, but that doesn't matter here. With boost::variant, you simply derive your visitor class from the static_visitor class, which lets you visit the types in a boost::variant via the call operator. When you want to do always the same for all types, you simply can add a template method version of the call operator...

Time Zone Database Parser -- Howard Hinnant

This page fully documents a library to handle time zones in C++11 and C++14.

The library documentation

by Howard Hinnant

From the article:

Introduction

I had just completed writing date, which is a library for extending <chrono> into the realm of calendars, and I was looking around for the most challenging date time problem I could find with which I could demonstrate the power of this new library. "I know," I said to myself, "I'll handle all the world's time zones, and maybe even leap seconds!" Thus began my journey into a rabbit hole which I knew existed, but had never truly appreciated the intricacies of.

This library adds timezone and leap second support to this date library. This is a separate library from date because many clients of date do not need timezone nor leap second support, and this support does not come for free (though the cost is quite reasonable).

This library is a complete parser of the IANA Time Zone Database. This database contains timezone information that represents the history of local time for many representative locations around the globe. It is updated periodically to reflect changes made by political bodies to time zone boundaries, UTC offsets, and daylight-saving rules. The database also maintains a list of leap seconds from 1972 through the present.

The IANA Time Zone Database contains four specific types of data:

Zone: A geographic location with a human-readable name (e.g. "America/New_York") which specifies the offset from UTC and an abbreviation for the zone. This data includes daylight saving rules, if applicable, for the zone. This data is not only the rules currently in effect for the region, but also includes specifications dating back to at least 1970, and in most cases dating back to the mid 1800's (when uniform time was first introduced across regions larger than individual towns and cities).

Rule: A specification for a single daylight-saving rule. This helps implement and consolidate the specifications of Zones.

Link: This is an alternative name for a Zone.

Leap: The date of the insertion of a leap second.

The library documented herein provides access to all of this data, and offers efficient and convenient ways to compute with it. And this is all done based on the date library, which in turn is based on the C++11/14 <chrono> library. So once you've learned those fundamental libraries, the learning curve for this library is greatly eased.

A date and time library for use with C++11 and C++14 -- Howard Hinnant

This paper fully documents a date and time library for use with C++11 and C++14.

Library documentation:

by Howard Hinnant

From the article:

Implementation

This entire library is implemented in a single header: date.h and is open source (with generous open source terms — not generous enough? Contact me, I'm flexible).

It uses the algorithms from chrono-Compatible Low-Level Date Algorithms. If you want detailed explanations of the algorithms, go there.

It performs best with C++14, which has vastly improved constexpr rules. However, the library will auto-adopt to C++11, sacrificing several constexpr declarations. In C++11, this will effectively transfer some computations that should be done at compile-time to run-time. Porting to C++98/03 has not been attempted.

Overview

This library builds date and date/time support on top of the <chrono> library. However it does not support timezones nor leap seconds. A separate library is provided, built on top of this one, for timezone and leap second support. Thus you only pay for such support if you need it.

RVO V.S. std::move -- Zhao Wu

Discussion about the RVO optimization technique & std::move.

RVO V.S. std::move

by Zhao Wu

From the article:

To summarize, RVO is a compiler optimization technique, while std::move is just an rvalue cast, which also instructs the compiler that it's eligible to move the object. The price of moving is lower than copying but higher than RVO, so never apply std::move to local objects if they would otherwise be eligible for the RVO.

Efficient optional values -- Andrzej Krzemieński

Andrzej goes into some details of optional values in his recent blog post.

Efficient optional values

by Andrzej Krzemieński

From the article:

What do you use Boost.Optional for? In my experience, the answer was typically one of the following:

  1. Because my type T has no null state (like -1) that would indicate that I have no proper value.
  2. Because, I need to perform a two-phase initialization (I cannot initialize my T yet, but I already need it alive).
  3. Because I need an interface that would indicate to the type system that my value may not be there and that its potential absence should be checked by the users.

In this post we will focus exclusively on the third motivation.

Bitesize Modern C++: using aliases--Glennan Carnie

Do you know how to use type aliasing?

Bitesize Modern C++: using aliases

by Glennan Carnie

From the article:

In a C++ program it is common to create type aliases using typedef. A type alias is not a new type, simply a new name for an existing declaration. Used carefully, typedef can improve the readability and maintainability of code – particularly when dealing with complex declarations...

Programmatic access to the call stack in C++--Eli Bendersky

The call stack can be accessed without debugger too:

Programmatic access to the call stack in C++

by Eli Bendersky

From the article:

Sometimes when working on a large project, I find it useful to figure out all the places from which some function or method is called. Moreover, more often than not I don't just want the immediate caller, but the whole call stack. This is most useful in two scenarios - when debugging and when trying to figure out how some code works...

PeriodicFunction--Tony “Bulldozer00” (BD00) DaSilva

An interesting article showing how to call a function periodically:

PeriodicFunction

by Tony “Bulldozer00” (BD00) DaSilva

From the article:

In the embedded systems application domain, there is often the need to execute one or more background functions at a periodic rate. Before C++11 rolled onto the scene, a programmer had to use a third party library like ACE/Boost/Poco/Qt to incorporate that functionality into the product. However, with the inclusion of std::thread, std::bind, and std::chrono in C++11, there is no longer the need to include those well-crafted libraries into the code base to achieve that specific functionality...

Three years of Meeting C++

A little more then 3 years ago, Meeting C++ launched:

Three years of Meeting C++

by Jens Weller

From the article:

Its now a little more then 3 years that I went public with the plans for a new C++ Conference. Today, Meeting C++ is much more, it has become a platform for C++ User Groups, but also a great source of C++ related news. I had no idea, how much my life would change, when I started to make serious plans for the very first Meeting C++ conference...