Range Constrained Types in C++

Posted on Fri 05 September 2014 in misc View Comments • Tagged with C++, Ada

One of the first things a new Ada programmer will learn is the ability to define constrained type. Which means that one can restrict the values that can be assigned to a variable of this specific type.

For example:

subtype Positive is Integer range 1 .. Integer'Last;

Being a subtype …


Continue reading

Template Argument Deduction

Posted on Sun 04 May 2014 in misc View Comments • Tagged with C++, generics

With automatic template deduction, it is possible to omit the template argument when instantiating a template function. The compiler will deduce the type from the actual parameter sent to the function. This is of course assuming there are no ambiguities.

For example:

template<class T>
T max(T x, T …

Continue reading