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

Transfer Functions

Transfer Functions In this post, we introduce the idea of transfer functions in the context of signal processing. In particular, we distinguish between the case of continuous-time signals (such as an analogue circuit board) and discrete-time signals used in DSP. Continuous Systems Laplace transform The Laplace transform of a function f(t)f(t)f(t) is given by: F(s)=L(f(t))=∫0∞f(t)e−stdt … Read more

Multithreading

What is multithreading? Multithreading allows a single process to execute multiple parts of a program simultaneously. Concurrency and Parallelism Concurrency is the ability to handle multiple tasks at the same time. A computer can run tasks concurrently even if it only has a single CPU. The operating system will schedule the execution of concurrent tasks … 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