Monthly Archives: August 2015

Bitesize Modern C++ : Range-for loops

Technical Consultant at Feabhas Ltd
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.
Glennan Carnie

If you’re using container classes in your C++ code (and you probably should be, even if it’s just std::array) then one of the things you’re going to want to do (a lot) is iterate through the container accessing each member in turn.

Without resorting to STL algorithms we could use a for-loop to iterate through the container.

If the above is baffling to you there are plenty of useful little tutorials on the STL on the Internet (For example, this one)

We could […]

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

Bitesize Modern C++: std::initializer_list

Technical Consultant at Feabhas Ltd
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.
Glennan Carnie

An aggregate type in C++ is a type that can be initialised with a brace-enclosed list of initialisers. C++ contains three basic aggregate types, inherited from C:

arrays
structures
unions

Since one of the design goals of C++ was to emulate the behaviour of built-in types it seems reasonable that you should be able to initialise user-defined aggregate types (containers, etc.) in the same way.

A std::initializer_list is a template class that allows a user-defined type to become an aggregate type.

When initialiser list syntax is […]

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