I am pleased to announce that my book on modern C++ programming has been published by PacktPub. The book is called Modern C++ Programming Cookbook and can be ordered at packtpub.com and Amazon. ISBN of the book is 9781786465184. The complete table of contents is available below.

The front cover

The book is organized in recipes, much like a cookbook (therefore the name). These recipes are organized in sections that introduce you to the topic, list any necessary pre-requisites and then explain how to do something and how that works. Throughout 112 recipes, the book covers both language and library features from C++11, C++14 and C++17, including the libraries for strings, containers, algorithms, iterators, input/output, regular expressions, threads, filesystem, atomic operations, and utilities. Besides that, there is a chapter for patterns and idioms and one dedicated for testing frameworks, that covers everything you need to know to get started with Boost.Test, Google Test and Catch.

This book is intended for all C++ developers, regardless of their experience. The beginner and intermediate developers will benefit the most from the book in their attempt to become prolific with C++. Experienced C++ developers, on the other hand, will find a good reference for many C++11, C++14, and C++17 language and library features that may come in handy from time to time. However, the book requires prior basic knowledge of C++, such as functions, classes, templates, namespaces, macros, and others. If you are not familiar with C++ at all, you should first read an introductory book to familiarize yourself with the core aspects.

Although C++17 has not yet been ratified as an ISO standard, the final version that is up for the ballot is well defined. In my book I discuss most of the important language and library features that made it into C++17. The C++17 features discussed in the book are:

  • structured bindings
  • fold expressions
  • constexpr if
  • new attributes ([[fallthrough]], [[nodiscard]], [[maybe_unused]])
  • new type deduction rules for list initialization
  • range based for loops improvements
  • general form of lambda expressions
  • std::invoke() and std::apply()
  • static_assert changes
  • non-member container access functions std::data(), std::size(), and std::empty()
  • std::search() searchers (Boyer-Moore and Boyer-Moore-Horspool)
  • chrono changes (floor(), round(), ceil(), and abs())
  • std::any
  • std::optional
  • std::variant (2 recipes)
  • std::string_view
  • std::scoped_lock
  • filesystem library (5 recipes)
  • shared_ptr and unique_ptr changes

All the samples in the book have been tested with VC++ 2017 (where possible), GCC 7 and Clang 5. All the language and library features discussed in the book are available with these versions of the mentioned compilers, except for a few exceptions for VC++. At this time, the following features are still not supported in VC++:

  • structured bindings
  • fold expressions
  • constexpr if
  • searchers for std::search()

If you do not have the latest versions of these compilers, you can try all the samples in the book with an online compiler. gcc and Clang are available at wandbox.org and VC++ is available at webcompiler.cloudapp.net.

Table of contents

  1. Learning Modern Core Language Features
    • Using auto whenever possible
    • Creating type aliases and alias templates
    • Understanding uniform initialization
    • Understanding the various forms of non-static member initialization
    • Controlling and querying object alignment
    • Using scoped enumerations
    • Using override and final for virtual methods
    • Using range-based for loops to iterate on a range
    • Enabling range-based for loops for custom types
    • Using explicit constructors and conversion operators to avoid implicit conversion
    • Using unnamed namespaces instead of static globals
    • Using inline namespaces for symbol versioning
    • Using structured bindings to handle multi-return values
  2. Working with Numbers and Strings
    • Converting between numeric and string types
    • Limits and other properties of numeric types
    • Generating pseudo-random numbers
    • Initializing all bits of internal state of a pseudo-random number generator
    • Using raw string literals to avoid escaping characters
    • Creating cooked user-defined literals
    • Creating raw user-defined literals
    • Creating a library of string helpers
    • Verifying the format of a string using regular expressions
    • Parsing the content of a string using regular expressions
    • Replacing the content of a string using regular expressions
    • Using string_view instead of constant string references
  3. Exploring Functions
    • Defaulted and deleted functions
    • Using lambdas with standard algorithms
    • Using generic lambdas
    • Writing a recursive lambda
    • Writing a function template with a variable number of arguments
    • Using fold expressions to simplify variadic function templates
    • Implementing higher-order functions map and fold
    • Composing functions into a higher-order function
    • Uniformly invoking anything callable
  4. Preprocessor and Compilation
    • Conditionally compiling your source code
    • Using the indirection pattern for preprocessor stringification and concatenation
    • Performing compile-time assertion checks with static_assert
    • Conditionally compiling classes and functions with enable_if
    • Selecting branches at compile time with constexpr if
    • Providing metadata to the compiler with attributes
  5. Standard Library Containers, Algorithms, and Iterators
    • Using vector as a default container
    • Using bitset for fixed-size sequences of bits
    • Using vector for variable-size sequences of bits
    • Finding elements in a range
    • Sorting a range
    • Initializing a range
    • Using set operations on a range
    • Using iterators to insert new elements in a container
    • Writing your own random access iterator
    • Container access with non-member functions
  6. General Purpose Utilities
    • Expressing time intervals with chrono::duration
    • Measuring function execution time with a standard clock
    • Generating hash values for custom types
    • Using std::any to store any value
    • Using std::optional to store optional values
    • Using std::variant as a type-safe union
    • Visiting a std::variant
    • Registering a function to be called when a program exits normally
    • Using type traits to query properties of types
    • Writing your own type traits
    • Using std::conditional to choose between types
  7. Working with Files and Streams
    • Reading and writing raw data from/to binary files
    • Reading and writing objects from/to binary files
    • Using localized settings for streams
    • Using I/O manipulators to control the output of a stream
    • Using monetary I/O manipulators
    • Using time I/O manipulators
    • Working with filesystem paths
    • Creating, copying, and deleting files and directories
    • Removing content from a file
    • Checking the properties of an existing file or directory
    • Enumerating the content of a directory
    • Finding a file
  8. Leveraging Threading and Concurrency
    • Working with threads
    • Handling exceptions from thread functions
    • Synchronizing access to shared data with mutexes and locks
    • Avoiding using recursive mutexes
    • Sending notifications between threads
    • Using promises and futures to return values from threads
    • Executing functions asynchronously
    • Using atomic types
    • Implementing parallel map and fold with threads
    • Implementing parallel map and fold with tasks
  9. Robustness and Performance
    • Using exceptions for error handling
    • Using noexcept for functions that do not throw
    • Ensuring constant correctness for a program
    • Creating compile-time constant expressions
    • Performing correct type casts
    • Using unique_ptr to uniquely own a memory resource
    • Using shared_ptr to share a memory resource
    • Implementing move semantics
  10. Implementing Patterns and Idioms
    • Avoiding repetitive if…else statements in factory patterns
    • Implementing the pimpl idiom
    • Implementing the named parameter idiom
    • Separating interfaces from implementations with the non-virtual interface idiom
    • Handling friendship with the attorney-client idiom
    • Static polymorphism with the curiously recurring template pattern
    • Implementing a thread-safe singleton
  11. Exploring Testing Frameworks
    • Getting started with Boost.Test
    • Writing and invoking tests with Boost.Test
    • Asserting with Boost.Test
    • Using test fixtures with Boost.Test
    • Controlling output with Boost.Test
    • Getting started with Google Test
    • Writing and invoking tests with Google Test
    • Asserting with Google Test
    • Using test fixtures with Google Test
    • Controlling output with Google Test
    • Getting started with Catch
    • Writing and invoking tests with Catch
    • Asserting with Catch
    • Controlling output with Catch


It took about eight months to complete this book and I got a lot of help from several people that I would like to thank to. First of all, is the team at PacktPub; although there were more people involve that I actually am aware of, I would like to thank Anurag Ghogre, Subhalaxmi Nadar and Nitin Dasan for all the help they provided throughout this time and the work they put in the project, as well as the other people that were involved with this book. I also want to thank David Corbin, whom I know for many years as “The CPU Wizard”, for reviewing the book and providing valuable feedback that made the book better. And last, but not least, I want to thank my wife for putting up with me through the many days and nights that I worked on this project.

, , , , , , , , Hits for this post: 6327 .

NuGet has recently added support for native projects. This simplifies a lot deployment of native libraries. Even though cpplinq is not a big library (in fact is just a header file) I have created a NuGet package so that you are able to automatically add it to your project.

Here is what you have to do.

  1. Make sure you have NuGet 2.5 or newer, otherwise the NuGet package manager won’t show up in your VC++ projects.
  2. In the context menu for your project choose Manage NuGet Packages…
  3. Search for cpplinq and install the package.
  4. Include the cpplinq.hpp header and start using the library. Here is a sample to test that everything is all right.

Notice that all the settings for library (such as adding the proper entry for the include directories or defining NOMINMAX so that min and max macros will not be defined for the project) are automatically performed, so you can focus on coding.

, , , , , , , Hits for this post: 43143 .

Microsoft has made available the release candidates for the new Windows and the new Visual Studio tool set. Some of the products have been renamed:

  • Windows Server 2012 is the new name for Windows 8 “Server”
  • Visual Studio 2012 is the new name for Visual Studio 11

MSDN subscribers can download them from their account. If you’re not a subscriber you can use the following links:

You can read more about these releases here:

The only thing I’d like to mention at this point is that after butchering the Windows logo (no, I don’t believe in the ingenuity of the light blue rectangle) someone felt the need to do the same with the Visual Studio logo. And if I could live with the new Windows logo (the color is awful) the new Visual Studio logo is huge failure, in my opinion.

Yes, that’s right, the one in the right is the new VS2012 logo.

After seeing the things Microsoft has done to Windows and Visual Studio UI (especially the colors in Windows that knock you in the head and, the opposite, the lack of colors in VS) it looks like all UI experts left to Apple.

, , , , , Hits for this post: 38541 .

This Wednesday Google released version 11 of the Chrome Browser. One of the most important addition was the support for speech recognition for English. One can enable speech recognition in an input field by adding the x-webkit-speech proprietary attribute, like in this example:

The result should look like this (of course, in Chrome 11, in the other browsers it looks just like a normal input):

You can press the microphone icon and speak. The browser sends the recording to the Google servers, where the speech is transformed into text, which is then displayed in the input field.

While this all is great, it doesn’t work that well, at least not with the English accent of a Romanian. It does work well with simple text such as “hello world”, “chrome 11”, “a beautiful day” or “show me the money”. However, in my tests, most of the time, the recognition failed. For instance “speech input” is sometimes recognized as “speaking book”. “twenty eleven” was most of the time recognized as 27, and very rarely as 2011. For “this is the year twenty-eleven” I got “this is beer 37”, which is probably the number of beers the service had earlier :). When trying “nothing else matters” I got “smoking a snickers”, “the king of snickers” and “latino snickers” until it finally figured out the correct text. So then I asked the browser “can you handle a longer sentence?” and the answers were “200 number centos”, “can you send unknown person”, “to handle a number sentence”, “200 number sentence”, “can you endorse a number sentence”, “can you handle a medical center”, “can you handle the number symptoms”, “can you pandas syndrome symptoms”, “kings honda center”, etc. etc. No matter what pronunciation I tried, it wasn’t able to pick the right text.

My conclusion is that in theory such a feature is great, but in practice Google still have a lot to work on it.

You can try it out here (with Chrome 11).

You can read more about HTML5 features in this presentation at slides.html5rocks.com.

, , , Hits for this post: 26163 .

Congratulations to Paula Seling and Ovi who won the 3rd place in the Eurovision Song Contest 2010. I linked the winning song too, but I think we could have actually won this year. The good things is that unlike previous years, the best songs ended at the top, even if the preferences order differs from person to person.

, Hits for this post: 12831 .

I am currently in Oslo for Visma Developer Days 2010, a conference for developers and QAs within Visma R&D and partners, which ended today. There were about 300 people here from five countries. I’ve attended very interesting keynotes on open software, HTML5, Silverlight 4, DITA and Documentation 2.0 and presentation on various topics, ranging from deployment, automated tests or writing sustainable APIs, to SQL Server profiler, meta programming with T4, and other related to company specific products or processes. I also delivered a short presentation on concurrency with a focus on the new parallel libraries and tools from Visual Studio 2010.

Here are some pictures from Oslo.

National day, celebrated on May 17, draws lots of people dressed in national costumes.

Paula Seling and Ovidiu Cernauteanu, Romanian contestants for the Eurovision Song Contest 2010, rehearsing in front of the City Hall.

On board of Fram, the famous ship that made three trips to the Artic and Antarctic regions under Fridtjof Nansen, Otto Sverdrup, and Roald Amundsen.

, , Hits for this post: 14097 .

Today Microsoft release officially Visual Studio 2010 and .NET Framework 4.0, with five major release events and many others across the globe. You can download it from MSDN. Those that don’t have an MSDN subscription can try the evaluation versions available here. Express editions are still available for free and can be downloaded from here.

During past months I have wrote various posts about the changes and new features for Visual C++. A summary of these articles are available here.

An important change in Visual Studio 2010 is that F#, now at version 2.0, is bundled in the IDE, just as the other languages, C++, C# and VB.NET. After 7 years in development it had become a first class language with today’s release.

More information about the release can be found here:

Hits for this post: 28612 .

Windows 7 RTM and Windows Server 2008 R2 RTM are now available for download on MSDN for MSDN and TechNet subscribers. Currently, the only available bits are in English. The other languages will become available on October 1st. Volume License customers with an existing Software Assurance license will be able to download the bits starting tomorrow.

For more information on these releases check the Windows Team Blog.

Update: Windows Server 2008 R2 is not yet available.

, , , , , , Hits for this post: 39105 .

Romanians won two of the nine awards at the 2009 Imagine Cup in Cairo: Software Design, the most important category, won by Sytech team, Adrian Buzgar, Calin Juravle, Andreas Resios, and IT Challenge, won by Cosmin Ilie.

This year’s theme was “Imagine a world where technology helps solve the world’s toughest problems.” About 300.000 students from 142 countries took part in the 2009 competition.

I want to congratulate Adrian, Calin, Andreas and Cosmin for their achievement, but also all the other winners and finalists.

Update: Here is Somasegar talking about Imagine Cup 2009.

Hits for this post: 11766 .

I am please to announce the launch of Sharparena.com, a developer community focused on the .NET framework and the # languages, C#, F# and J#.

This is an English site where you can ask questions about C#, F#, J# and the .NET framework in general, publish articles and stay up to date with news about the development on the .NET framework.

Here are some links:

On the main site you’ll find a series of FAQs about using the site. Consider reading the following for registering and publishing:

See you there!

, , , Hits for this post: 22574 .