In programming, a function is a block of code that performs a computational task. (In practice, people write functions that perform many tasks, which is not very good, but it’s a topic beyond the purpose of this article). Functions are a fundamental concept of programming languages and C++ makes no exception. In fact, in C++ there is a large variety of functions that has evolved over time. In this article, I will give a brief walkthrough of this evolution starting with C++11. Since there are many things to talk about, I will not get into too many details on these topics but will provide various links for you to follow if you want to learn more.
Tag: C++11
C++ rules for special member functions
C++ has several special member functions that are defined by the compiler even if not defined by the user. These special member functions are the default constructor, the copy constructor, the copy assignment operator, the move constructor, the move assignment operator, and the destructor. However, there are many rules for what is defined and in which circumstances. For instance, if no special member function is defined by the user then all of them are implicitly defined by the compiler. On the other hand, if a copy constructor or copy assignment operator is defined by the user, then the move constructor and move assignment operator are not defined by the compiler. To make it easier to comprehend all the rules, the following table describes what is defined by the compiler based on what is defined by the user.
My book Modern C++ Programming Cookbook has been published
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. The ISBN of the book is 9781786465184. The complete table of contents is available below. The book is organized in recipes, much…
Dining philosophers in C++11: Chandy-Misra algorithm
In my previous post, Dining Philosophers in C++11, I have provided an implementation for the dining philosophers problem using modern C++ features, such as threads and mutexes. However, it was noted in the comments that the implementation did not prevent the philosophers starving to death when you remove the waiting times. An algorithm that prevents…
Dining Philosophers in C++11
UPDATE: for an implementation of the Chandy/Misra solution see Dining philosophers in C++11: Chandy-Misra algorithm The problem of the dining philosophers, first proposed by Edsger Dijkstra and reformulated by Tony Hoare, is a famous problem for concurrent programming that illustrates problems with synchronizing access to data. The description of the problem, taken from Wikipedia, is…
MFC Collection Utilities library
This project has been moved to GitHub. New location: https://github.com/mariusbancila/mfccollectionutilities C++11 has provided support for range-based for loops. They allow iterating over the elements of a range without using an index. std::vector<int> v = {1, 2, 3, 4, 5}; for(auto& e : v) e *= 2; However, if you try the following MFC code you…
cppconlib: A C++ library for working with the Windows console
This project has been moved to GitHub. New location: https://github.com/mariusbancila/cppconlib Many years ago I published on my blog a helper class for working with the Windows console that was wrapping the Windows console API. Looking back at it I realized it was a pretty naive implementation. So I decided to start a new and make…
Beware of parallelization
A recent question on stackoverflow raised the problem of a fast algorithm to count the unique colors in an image (Faster algorithm to check the colors in a image). My answer what that this kind of problems are suited for parallelization. However, parallelization may only help when used judiciously. To demonstrate the point I have…
UNICODE support in the C++ Standard
The Oxford meeting of the ISO C++ standards committee between 15-20 April resulted in new features beeing into the draft paper of the C++0x standard. One of the features refer to Unicode support: a new header, called <cuchar>, was introduced. This header makes available new built-in types char16_t and char32_t, as well as new prefixes…