Author Archives: Glennan Carnie

About Glennan Carnie

Glennan is an embedded systems and software engineer with over 20 years experience, mostly in high-integrity systems for the defence and aerospace industry.

He specialises in C++, UML, software modelling, Systems Engineering and process development.

Traits classes

Introduction

In this final article we’ll have a look at the issue of communicating template type information between different template instantiations, and have a look at the Traits mechanism as a method of solving these

Posted in C/C++ Programming | Tagged , , , , , , , | 3 Comments

Template specialisation

Introduction

Welcome back to the wonderful world of templates.

So far, we have looked at what are known as base templates. In this article we’re going to look at one of the more confusing aspects of templates – specialisation. The choice of the word specialisation is unfortunate, as many confuse it with inheritance and sub-typing; in this case specialised means “more

Posted in C/C++ Programming | Tagged , , , , , | 6 Comments

Templates of templates

Introduction

In this brief article we’ll have a look at the topic of building template classes whose parameters are themselves templates.

I’m assuming you’re reasonably familiar with template classes.  If not, here’s a quick

Posted in C/C++ Programming | Tagged , , , , | 10 Comments

Variadic templates

Introduction

In this article we’re going to look at a new feature of templates in C++11 – the concept of the variadic template.

Variadic templates allow us to create functions and classes, not only with generic types, but also a variable number of generic

Posted in C/C++ Programming | Tagged , , , , , , | 1 Comment

Template member functions

Introduction

Previously we’ve looked at template functions and we’ve looked at template classes. This time, let’s look at what happens when you combine

Posted in C/C++ Programming | Tagged , , , , , , , , , , | 1 Comment

Templates and polymorphism

Introduction

Template functions and classes tend to cause consternation amongst programmers. The conversation tends to go something like this:

I understand the syntax of templates (although it’s ugly)
I get the idea of replacing function-like macros with template functions
I can see the application of template classes for containers
Most containers and generic functions are library code
I don’t write libraries
What’s the point of me using templates?

In this article we’re going to look at an application of templates beyond writing library code – replacing run-time polymorphism […]

Posted in C/C++ Programming | Tagged , , , , | 3 Comments

Template inheritance

Introduction

Previously we looked at template class syntax and semantics. In this article we’ll extend this to look at inheritance of template

Posted in C/C++ Programming | Tagged , , , , , | 9 Comments

Template classes

Introduction

Last time we looked at template functions, which introduced the concept of generic programming in C++.

This time let’s extend the idea of generic programming to

Posted in C/C++ Programming | Tagged , , , , | 2 Comments

An introduction to C++ templates

Introduction

Templates are a very powerful – but often very confusing – mechanism within C++. However, approached in stages, templates can be readily understood (despite their heinous syntax).

The aim of this series of articles is to guide beginners through the syntax and semantics of the foundation concepts in C++ template

Posted in C/C++ Programming | Tagged , , , , , | 9 Comments

Demystifying C++ lambdas

A new (but not so welcome?) addition

Lambdas are one of the new features added to C++ and seem to cause considerable consternation amongst many programmers. In this article we’ll have a look at the syntax and underlying implementation of lambdas to try and put them into some sort of

Posted in C/C++ Programming | Tagged , , , , , , | 39 Comments