O'Reilly logo

Boost C++ Application Development Cookbook by Antony Polukhin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enabling the usage of templated functions for integral types

It's a common situation, when we have a templated class that implements some functionality. Have a look at the following code snippet:

// Generic implementation
template <class T>
class data_processor {
    double process(const T& v1, const T& v2, const T& v3);
};

After execution of the preceding code, we have additional two optimized versions of that class, one for integral, and another for real types:

// Integral types optimized version template <class T> class data_processor { typedef int fast_int_t; double process(fast_int_t v1, fast_int_t v2, fast_int_t v3); }; // SSE optimized version for float types template <class T> class data_processor { double process(double v1, double v2, double ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required