Synchronizing Files with C++

In this post, we look at how to monitor a directory (and its subdirectories) so that we will be notified when a change occurs. We can use the Windows API to do this in C++. There are two APIs that can achieve this: FindFirstChangeNotification() ReadDirectoryChangesW() We will use ReadDirectoryChangesW() as this API provides useful information … Read more

Categories C++

Butterworth Filter Design in C++

A low-pass filter is a filter which removes high frequencies from a signal. Low-pass filters are very useful in digital audio applications. For example: Removing artifacts when resampling. Emulating the response of a speaker cabinet. Removing harsh sounding frequencies introduced by wave shaping effects such as overdrive. In this post, we will be looking at … Read more

Ranges in C++20

In C++20, the range concept requires that an object has both an iterator, and an end sentinel. This is useful in the context of standard collections, in particular when developing algorithms (i.e. template functions) which operate on collections. Motivation Suppose we have a vector of values which we want to sort: std::vector<int> values = {10, … Read more

Concepts in C++20

Concepts allow us to add requirements to template arguments. There are different types of constraints, e.g. Syntactic requirement – e.g. what operations need to be defined. Semantic requirements – i.e. what behaviour is required of the operations. For example, an iterator needs to have begin() and end() operations and also needs to implement the increment … Read more

Modules in C++20

C++ Modules

What are modules? Modules are the new C++20 method for importing functions and classes from external libraries and separate translational units. Modules provide an alternative to using header files. Some of the benefits of modules are: No need to write separate files for the interface (.h) and the implementation (.cpp) Faster compile / recompile times … Read more

A File Server in C++

Writing a cross-platform HTTP file server in C++ is not a simple task. Back in the days of C++03 it was particularly difficult as the standard library was very limited. Some of the requirements for writing a HTTP server are: Sockets Cryptographically secure random number generate Threads and thread synchronisation File access Any POSIX based … Read more

C++14 Features

In this post we discuss some of the key features added in C++14. In particular, we look at the following enhancements: Language features: Automatic return type deduction Generic lambdas Extended constexpr functionality Standard library features: std::make_unique Additional user-defined literals Language features Automatic return type deduction It is now possible for the compiler to deduce the … Read more

Trailing Return Type

The trailing return type feature was added in C++11. This feature allows you to specify the return type after a function declaration instead of before. In order to see how this is can be useful, we shall look at a simple example. Suppose we have an Employee class which records an employee’s salary and whether … Read more

Gaussian Elimination with Partial Pivoting

Gaussian elimination is a direct method for solving a linear system of equations. A linear system is a set of simultaneous equations (linear) in several variables. In theory, solving such a system algebraically is straightforward. First, we eliminate the first variable either by substitution or appropriate row operations. We then continue to eliminate the second … Read more

In-class Initialisation of Data Members

In C++03, only const static members of integral type can be initialised directly in the class. C++11 allows members to be initialised in-class. class Test { public: const static int x = 0; // C++03 int y = 0; // C++11 only }; We can also initialise objects e.g. strings: class Test { public: std::string … Read more