PSA: Add noexcept When Migrating to Visual C++ 2015

July 30, 2015

tl;dr -- when migrating from Visual C++ 2013 to Visual C++ 2015, make sure that (1) your destructors do not throw exceptions, and (2) your move constructors are marked noexcept if they do not throw exceptions. Less than a year ago, I described some of the reasons why noexcept is an important C++ language feature that lurks in the background and waits for the right moment to bite you in the neck. Specifically, destructors and move constructors should ideally be marked as noexcept. For move constructors, this "ideally" means there are corner cases where performance won't be optimal if you don't mark the move constructor noexcept; for destructors,...
no comments

Materials from NDC Oslo 2015

July 16, 2015

It was my first time at NDC Oslo, and my first time in Norway as well. I was really impressed with the city of Oslo, with the conference venue, with the energy that could be felt all around the halls and expos, and with the great hospitality of the conference organizers. I'm really looking forward to be back at NDC London or NDC Oslo (and who knows, maybe NDC Australia too?). In the meantime, here are the materials from my two talks, both of which were recorded and are already available online to watch. Swift: Apple's New Programming Language for iOS and...
no comments

Obtaining the CoreCLR DAC DLL for Windows Phone

July 6, 2015

Three years ago I blogged about obtaining SOS.dll and mscordacwks.dll indirectly from the Microsoft KB websites in case you only have a dump from the production system but can't gain access to copy these files over. (Reminder: SOS.dll is a WinDbg extension for debugging .NET processes and dump files. The DAC, or mscordacwks.dll, is a helper library used by SOS to access the inner workings of a specific CLR version's data structures. The DAC is also used by ClrMD, a managed library that provides an API replacement for the SOS extension commands.) It turns out that for Windows Phone applications (using the Windows Phone...

Defensive Programming Gone Too Far, Or Respecting Your Contracts

June 30, 2015

In the last few months, I've heard this argument more than once. And whenever I have to repeat my counter-arguments, I know it is time for a blog post. So here goes, a short take on defensive programming gone too far. Suppose you have the following, extremely boring, C++ function (the language is not of any importance for this exercise): bool add_task(employee& emp, task const& t) { if (emp.task_count() > 10) return false; emp.add_task(t); return true; } And here's the argument I'm going to be fighting against until I draw my last breath: The function needs to be more...

Materials From This Year’s First SDP

June 5, 2015

Another SDP conference is behind us! It's been an incredible week of brand new technology talks, meeting customers, jogging across the Tel-Aviv beach, and also getting a pretty bad cold from the air conditioning at the conference hotel. We are already hard at work planning the next conference, but in the meantime, here are the materials from my talks this year. Elements of Modern C++ Style This talk, based on materials from our Modern C++ course, introduced four key tenets which I believe are fundamental to modern C++ code: letting the compiler help you out (with language features like auto and...
tags: ,
no comments

Wrapping Up DevWeek 2015

April 2, 2015

Just a couple of months ago, I agreed to deliver eight breakout sessions and a full-day workshop at DevWeek 2015. And no, I don't have any regrets -- but it was definitely a very packed week with lots of room changes and, more importantly, context switches from one topic to another. If you've been to DevWeek this year, I'm sure you enjoyed it: it's getting better year over year, and this is my third one so far. Below you can find the materials for my eight sessions. If you've been to my workshop and haven't got the materials, please contact...

DevWeek Workshop: Making The Most Of C++ 11/14

March 19, 2015

It's been a few weeks since my last post. Should I apologize? I really should. But with eight sessions and a workshop at DevWeek, I hope to make up for it in the upcoming weeks. Anyway, next week I'm giving a workshop at DevWeek, titled Making The Most Of C++ 11/14. It's a distilled summary of modern C++ that every C++ developer has to be aware of. This is a slightly longer description that what was published on the conference website. The C++ language many of us are using today goes back more than thirty years. You might be using some “newer” features, such...
tags: ,
no comments

Implementing std::tuple From The Ground Up: Part 7, tuple_cat Take 2

February 22, 2015

This is the last post in the series. We have a fully functional tuple class, with a decent implementation of tuple_cat -- but some reservations about its performance. In this post we're going to improve it considerably, at the expense of making the implementation more difficult. The main problem with what we did in the previous post is that we are creating many temporary tuple objects. When concatenating n tuples, we create n-2 intermediate tuples that hold partial results. But can it be avoided? UPDATE (Feb 24): I forgot to credit Stephan T. Lavavej (a.k.a. STL, also the maintainer of Microsoft's STL)...
tags: ,
no comments

Implementing std::tuple From The Ground Up: Part 6, tuple_cat Take 1

February 13, 2015

We are almost done. We have a pretty functional tuple that supports almost every operation mandated by the Standard. With one major exception: tuple_cat. First, let's see what it does: auto t1 = tuple_cat(make_tuple(1), make_tuple(2)); // tuple<int, int>(1, 2) auto t2 = tuple_cat(t1, make_tuple(3), make_tuple(4)); auto t3 = tuple_cat(t1, t1, t2, t2); // t3 is a tuple of 12 ints: 1, 2, 1, 2, 1, 2, 3, 4, 1, 2, 3, 4 Hmpf. Obviously, tuple_cat is a variadic function template. tuple is itself a variadic class template, and we're now trying to build a variadic function template that takes any number of variadic class...
tags: ,
one comment

Implementing std::tuple from the Ground Up – Part 5: Tuple Non-Member Functions

February 3, 2015

After doing all the heavy lifting in the previous four installments (, , , ), this one is going to be very lightweight. We will implement a few simple tuple non-member functions and helpers. First, let's implement a very simple helper: tuple_size. It is a metafunction that returns the number of elements in the tuple. Exercise 11: Implement tuple_size. Solution: template <typename> struct tuple_size; // undefined base template template <typename... Types> struct tuple_size<tuple<Types...>> : std::integral_constant<size_t, sizeof...(Types)> { }; Well, that was easy. Let's do another: forward_as_tuple. The basic idea is that you provide a set of elements and get back a tuple that has lvalue or rvalue references depending...
tags: ,
one comment