Codexpert – 2015 Articles Summary

Microsoft Libraries and C++ Programming Language Using Lambdas in MFC Applications – Part 1: Sorting Arrays Presents how to sort MFC arrays using lambda expressions (C++11 and next). Using Lambdas in MFC Applications – Part 2: Replacing Callback Functions Shows examples of using lambda expressions (including nested lambdas) in MFC applications for replacing callback functions. … Read more

Binary literals and digit separators

The C++14 standard provides two new small features to the language: binary literals and digit separators. They are already available in Clang 3.4 and GCC 4.9 and now Visual Studio 2015 RC has implemented them. They may not be something you can’t live without, but sometimes it’s convenient to have them. Let’s have a look. … Read more

Using Lambdas in MFC Applications – Sorting Arrays

Beginning with Visual Studio 2010 which supports lambda expressions introduced by C++11 standard, you can handily sort an MFC array like in the following example: Sorting CStringArray by using a lambda expression // Example #1 // … CStringArray arr; arr.Add(_T(“John”)); arr.Add(_T(“Zorro”)); arr.Add(_T(“Sandy”)); arr.Add(_T(“Jimmy”)); // … bool bAscending = true; // … std::sort( arr.GetData(), // position … Read more

User defined literals

The C++ language defines various built-in literals (numerical, character, string, boolean and pointer) and a series of prefixes and suffixes to specify some of them. The suffix or prefix is part of the literal. auto b = true; // boolean auto s = “sample”; // const char[7] auto i = 128; // int auto d … Read more

Farewell to new and delete

C++11 introduced several smart pointers (residing in the <memory> header): std::shared_ptr: retains shared ownership of an object, that is destroyed when the last shared_ptr that holds a reference to it is destroyed or assigned another pointer. std::unique_ptr: retains sole ownership of an object, that is destroyed when the unique_ptr goes out of scope std::weak_ptr: retains … Read more