Blog

Quick Q: Why two null constructors for std::unique_ptr?

Quick A: The nullptr_t constructor was added later.

Recently on SO:

Why two null constructors for std::unique_ptr?

For (1), consider that it ensures that both the no-arg constructor unique_ptr() and null-pointer constructor unique_ptr(nullptr_t) have the same compile-time guarantees, i.e. both are constexpr. We can see the difference in §20.8.1.2:

constexpr unique_ptr() noexcept;
explicit unique_ptr(pointer p) noexcept;
...
constexpr unique_ptr(nullptr_t) noexcept
: unique_ptr() { }

Why the two were not combined into a single constructor with a default value is likely historical contingency.

With regards to (2), why we should care about constexpr despite having a non-trivial destructor, consider the answer given here:

constexpr constructors can be used for constant initialization, which, as a form of static initialization, is guaranteed to happen before any dynamic initialization takes place.

For example, given a global std::mutex:

std::mutex mutex;

In a conforming implementation (read: not MSVC), constructors of other objects can safely lock and unlock mutex, becuase std::mutex's constructor is constexpr.

CppCon 2015 C++: How I learned to stop worrying and love metaprogramming—Edouard Alligand

Have you registered for CppCon 2016 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 2015 for you to enjoy. Here is today’s feature:

C++: How I learned to stop worrying and love metaprogramming

by Edouard Alligand

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Horrible software engineering technique conceived in the forge of Hell or the Only True Way of doing C++ in 2015, template metaprogramming and its cohort of companion techniques are sure to create animation in a group of programmers.

What if we were to tell you that an actual software product, actually sold to real customers and in production for now several years has been built on it? What if we were to tell you that a lot of advanced template techniques helped us to build a better software faster?

This talk is all about real life examples of template metaprogramming, why they are useful and when and how you could use them in your own projects.

An update on the Meeting C++ Workshop Day

I finally can announce that the workshops will end with talks by James McNellis and Michael Caisse:

An Update on the workshop day

by Jens Weller

From the article:

Michael Caisse - boost.fusion: power to the tuples

    Tuples provide heterogeneous, compile-time containers; however, they can be difficult to use at run-time. Boost.Fusion brings together compile-time and run-time semantics to produce the STL of the meta-programming world. It is the machinery behind several Boost libraries and is a common element in many of the solutions provided by Ciere Consulting.


James McNellis - Practical C++ Coroutines

    One of the most interesting new features being proposed for C++ standardization is coroutines, formerly known as “resumable functions”. C++ coroutines are designed to be highly scalable, highly efficient (no overhead), and highly extensible, while still interacting seamlessly with the rest of the C++ language.

CppCon 2015 Parallelizing the C++ Standard Template Library—Grant Mercer & Danial Bourgeois

Have you registered for CppCon 2016 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 2015 for you to enjoy. Here is today’s feature:

Parallelizing the C++ Standard Template Library

by Grant Mercer & Danial Bourgeois

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

As the era of frequency scaling comes to an end, multi-core parallelism has become an essential focal point in computational research. Mainstream languages, however, have not yet adapted to take full advantage of parallelism provided by the hardware. While new languages such as Rust and Swift are catching on and implementing multi-core algorithms in their libraries, C++ has only started to do so. A parallel Standard Library could bring with it many positive features that users can begin taking advantage of.

This talk will focus around two standards proposals, N4409 and N4406. N4409 outlines the details of a parallel Standard Library and features of these new parallel algorithms. The complementary N4406 outlines abstractions to take advantage of various mechanisms for parallel execution. We will cover the reasons why the new Standard Library would be beneficial to C++ users and our experience implementing these algorithms in HPX. The presentation will address what exactly the two proposals define, the challenges we faced, and the results we collected. In addition, we will discuss extensions made to these proposals and the C++11/14 standard in HPX to support these semantics in a distributed environment.

Enum Bitfields: A Gentle Introduction to SFINAE

Jon Kalb's talk at the New York C++ Developer meetup based on Anthony Williams' article in Overload is now online:

Using enum structs as bitfields (slides)

by Jon Kalb

From the description:

Jon Kalb gave a talk on Enum Bitfields at the New York C++ Developers group 2016-07-12. The talk was based on an article by Anthony Williams that is a gentle introduction to SFINAE. It includes a few nice library development pointers.

 

 

CppCast Episode 64: Modules with Gabriel Dos Reis

Episode 64 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Gabriel Dos Reis, Principal Software Engineer at Microsoft to discuss C++ Modules.

CppCast Episode 64: Modules with Gabriel Dos Reis

by Rob Irving and Jason Turner

About the interviewee:

Gabriel Dos Reis is a Principal Software Development Engineer at Microsoft. He is also a researcher and a longtime member of the C++ community. His research interests include programming tools for dependable software. Prior to joining Microsoft, he was Assistant Professor at Texas A&M University. Dr. Dos Reis was a recipient of the 2012 National Science Foundation CAREER award for his research in compilers for dependable computational mathematics and educational activities.

Parameter or Argument?—Malte Langkabel

Did you know the difference?

Parameter or Argument?

by Malte Langkabel

From the article:

I often hear people getting confused when talking about parameters and arguments. That confusion grows even stronger when one of them knows the difference but the other one doesn’t. So let’s shed some light on this issue and spread the knowledge! Programming involves talking to each other but that doesn’t have to be more painful than it already is wink