Tag Archives: auto

Getting your head around auto’s type-deduction rules

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

Automatic type-deduction is perhaps one of the more divisive features of Modern C++.  At its core it’s a straightforward concept:  let the compiler deduce the type of an object from its initialiser.   Used in the right way this can improve the readability and maintainability of your code.

However, because auto is based on template type-deduction rules there are some subtleties that can catch the unwary programmer.

In this article we’ll have a look at auto in the context of the template type-deduction […]

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

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++ : auto

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

C++ is a statically-typed language, that is, you must explicitly declare the type of every object before use. The type of an object specifies

The amount of memory occupied
How the memory (bits) is interpreted
The operations allowable on the object

An object’s type is fixed at declaration – unless the programmer chooses to circumvent the type system using a cast.

Often for C++ objects specifying the type can be onerous:

C++11 allows automatic type-deduction to simplify the creation and maintenance of code.

The […]

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