July 2015

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

CppCon 2014 C++ Memory Model Meets High-Update-Rate Data Structures--Paul E. McKenney

Have you registered for CppCon 2015 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2014 for you to enjoy. Here is today’s feature:

C++ Memory Model Meets High-Update-Rate Data Structures

by Paul E. McKenney

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Highly performant and scalable techniques such as RCU and hazard pointers have been quite successful in read-mostly situations. However, there do come times when updates are necessary. It would be convenient if there was some general update-side counterpart to these techniques, but sadly there is not yet any such thing. Nevertheless, there are a number of specialized update-side techniques whose performance and scalability rival those of RCU and hazard pointers. This talk will discuss several of them, one of which is a solution to a challenge to the speaker at the 2014 Issaquah C++ standards committee meeting. This talk will also provide an outlook into the future of low-overhead scalable updates.

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.

SourceMeter for C/C++ with open-source SonarQube plugin released

FrontEndART has release a new version of their SourceMeter.

SourceMeter 7.0 released with support for C/C++

by FrontEndART team

From the article:

Most important product characteristics of SourceMeter:

  • Platform-independent command line tools
  • Transparent integration into build processes
  • Coding issue detection
  • Clone detection (copy-pasted source code fragments) extended with clone tracking and "clone smells"
  • Metrics calculation at component, file, namespace, class, function and method levels
  • C++14 support (almost complete, based on EDG front-end)
  • SonarQube plug-in

Online demo

 

CppCon 2014 Costless Software Abstractions for Parallel Architectures--Joel Falcou

Have you registered for CppCon 2015 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2014 for you to enjoy. Here is today’s feature:

Costless Software Abstractions for Parallel Architectures

by Joel Falcou

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Performing large, intensive or non-trivial computing on array like data structures is one of the most common task in scientific computing, video game development and other fields. This matter of fact is backed up by the large number of tools, languages and libraries to perform such tasks. If we restrict ourselves to C++ based solutions, more than a dozen such libraries exists from BLAS/LAPACK C++ binding to template meta-programming based Blitz++ or Eigen. If all of these libraries provide good performance or good abstraction, none of them seems to fit the need of so many different user types.

Moreover, as parallel system complexity grows, the need to maintain all those components quickly become unwieldy. This talk explores various software design techniques - like Generative Programming, MetaProgramming and Generic Programming - and their application to the implementation of a parallel computing librariy in such a way that:

- abstraction and expressiveness are maximized - cost over efficiency is minimized

We'll skim over various applications and see how they can benefit from such tools. We will conclude by discussing what lessons were learnt from this kind of implementation and how those lessons can translate into new directions for the language itself.

N4548: WG21 2015-07-20 Telecon Minutes -- Roger Orr

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N4548

Date: 2015-07-20

WG21 2015-07-20 Telecon Minutes

by Roger Orr

Excerpt:

"Move to direct the Convener to transmit the approved updated Concepts TS working paper (attachment ts.pdf r2) for publication." [...] There were no objections, so the poll was carried.

CppCon 2014 Hourglass Interfaces for C++ APIs--Stefanus DuToit

Have you registered for CppCon 2015 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2014 for you to enjoy. Here is today’s feature:

Hourglass Interfaces for C++ APIs

by Stefanus DuToit

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

C++ provides a much richer set of abstractions than C. Classes, templates, overloading, and other core C++ features can be leveraged for more readable syntax, better compile time typechecking, more open ended genericity and improved modularity. On the flip side, C89 still boasts some advantages over C++, especially when viewed through a pragmatic lens. C ABIs on many platforms have been stable for decades, practically every language supports binding to C code through foreign function interfaces, and including nearly any C89 header has a negligible effect on compile time on modern computers.

The Hourglass pattern provides the best of both worlds. It's a way to structure libraries that retains the pragmatic benefits of C89 while still providing C++'s richness both at an interface and implementation level. It makes providing bindings from other languages to C++ libraries easier, and insulates from ABI issues such as incompatibilities between debug and release variants of runtimes. This talk provides an overview of the pattern, teaches practical techniques for its implementation using C++98 and C++11, and shares experience from using the pattern in real world projects.

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.