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

Codexpert – 2014 Articles Summary

Microsoft Libraries Multiple-View File Explorer Shows how to easily make a Windows file manager with multiple views by using MFC framework and IExplorerBrowser interface. MFC Support for Direct2D – Part 1 Using the MFC D2D classes for making a simple image viewer. MFC Support for Direct2D – Part 2 Demonstrates how to easily make a … Read more

C++11: Let’s Write a “Hello Lambda!”

A lambda expression (aka lambda function), introduced in C++11 standard, is a simplified notation for defining an anonymous function object. However, its syntax and using may look weird for many people so let’s try to make a simple program to accommodate with it. // Example #1 #include <iostream> int main() { [] () mutable throw() … 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

C++11: non-member begin() and end()

One of the addition to the C++ 2011 standard that is perhaps not so much popularized is the non-member begin() and end(). In STL all containers have a non-static member begin() and end() methods that return an iterator to the beginning and the end of the container. Therefor iterating over a container could look like … Read more