ecl_type_traits Documentation


Extends c++ type traits and implements a few more to boot.


Provides some cross platform type traits above and beyond what is provided by c++.


Include the following at the top of any translation unit which requires this library:

        #include <ecl/type_traits.hpp>

        // The error interfaces
        using ecl::numeric_limits;
        using ecl::is_integral;
        using ecl::is_float;
        using ecl::is_signed;
        using ecl::is_unsigned;
        using ecl::is_byte;

You will also need to link to -lecl_type_traits.


Numeric Limits

This extends c++'s numeric_limits class for fundamental types, providing in addition, static constants that can be utilised as template arguments (as opposed to c macros or c++ functions in numeric_limits). For integral types, an example of the extras available:

        ecl::uint16 bits = NumericLimits<int>::bits;
        ecl::uint16 bytes = NumericLimits<int>::bytes;
        int j = NumericLimits<int>::one;
        int i = NumericLimits<int>::minimum;
        int k = NumericLimits<int>::maximum;

An example of some extras for a float type:

        ecl::uint16 bits = NumericLimits<float>::bits;
        ecl::uint16 bytes = NumericLimits<float>::bytes;
        // precision setting is a rough, but useful aid to bounding the accuracy for some math calculations
        NumericLimits<float>::Precision p = NumericLimits<float>::dummy_precision();
        // note, numeric_limits<float>::min() is the smallest 
        // positive value, this is the smallest negative value.
        float minimum = NumericLimits<float>::minimum;    
        float maximum = NumericLimits<float>::maximum;  

Note that it inherits the numeric_limits class, so all the functions therein can also be used.

Fundamental Type Traits

These are in the upcoming C++0x standard, so are only a temporary feature in the ecl. They are a subset and work just like boosts type traits. More will be added as needed. The code snippet below is for runtime code, but they're actually more useful with enable_if in determining which compile time template specialisations to instantiate.

        if ( is_float<double>::value ) {
          // take some action

The current list of type traits include:



Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:23