Custom Deleters for C++ Smart Pointers

Let’s say we have the following code: LegacyList* pMyList = new LegacyList(); ... pMyList->ReleaseElements(); delete pMyList; In order to fully delete an object we need to do some additional action. How to make it more C++11? How to use unique_ptr or shared_ptr here? Intro We all know that smart pointers are really nice things and we should be using them instead of raw new and delete.

READ MORE...

Notes on C++ SFINAE

This time I’d like to tackle a bit more complex problem: SFINAE. I’m not using this paradigm on a daily basis, but I’ve stumbled across it several times and I thought it might be worth trying to understand this topic. What is SFINAE? Where can you use it? Do you need this on a daily basis?

READ MORE...

C++ Status at the end of 2015

Maybe I’ll be boring with this note, but again I need to write that this was another good year for C++! Here’s a bunch of facts: Visual Studio 2015 was released with great support for C++14⁄17 and even more experimental features. Long-awaited GCC 5.0 was released at the beginning of the year.

READ MORE...

Errata and a Nice C++ Factory Implementation

I’ve finally got my copy of “Effective Modern C++”! The book looks great, good paper, nice font, colors… and of course the content :) While skimming through it for the first (or second) time I’ve found a nice idea for a factory method. I wanted to test it. The idea In the Item 18 there was described how to use std::unique_ptr and why it’s far better than raw pointers or (deprecated) auto_ptr.

READ MORE...

C++ Status at the end of 2014

This was a good year for C++! Short summary (language features): Clang supports C++14 GCC supports C++11 and most of C++14 (Full support in upcoming GCC 5.0) Intel 15.0 supports C++11 (some features on Linux/OSX only) Visual Studio tries to catch up with C++11, but it also introduces C++14 features as well… and it become (almost) free!

READ MORE...

Top 5 Beautiful C++ std Algorithms Examples

Some time ago I’ve seen an inspiring talk from CppCon 2013: “C++ Seasoning” by Sean Parent. One of the main points of this presentation was not to use raw loops. Instead, prefer to use existing algorithms or write functions that ‘wraps’ such loops. I was curious about this idea and searched for nice code examples.

READ MORE...

Tasks with std::future and std::async

Let us consider a simple task: “Use a worker thread to compute a value”. In the source code it can look like that: std::thread t([]() { auto res = perform_long_computation(); }; Now, you would like to obtain the result when the computation is completed. How to do it efficiently?

READ MORE...

C++ status at the end of 2013

C++11 conformance GCC 4.81 - 100% Clang 3.3 - 100% Intel 14.0 - 84% Visual C++ 2013 - 66% Another year is almost over so it is a good time to check what is going on with C++. This time more stats and real data compared to my post from the previous year.

READ MORE...

Auto keyword in C++11

// how does it work? auto i = 0; // ?? C++11 brings us a very useful set of tools. It adds fresh air to the hard life of a programmer. The updated syntax makes the language a more modern and easier to use. In this post let’s take a quick look at a nice keyword ‘auto’ that, at first sight might seem very simple.

READ MORE...

Book: The C++ Standard Library, 2nd

The C++ Standard Library: A Tutorial and Reference (2nd Edition)< /> We are still waiting for some more books about new C++ standard. Fortunately for us, some authors managed to write books even before C++11 is well “domesticated”. One of such examples is the book mentioned in the title of this post.

READ MORE...

Forward Declaration And a Pointer

Mister C was a cool guy. C could make amazing things with just ordinary text files. He used to grab bunch of them and produce magic binary forms. He could make a spinning cube, web server, or even an operating system. One time he was running through a plain header file.

READ MORE...