It'll only be of a benefit if the resulting inline code is smaller than the cost of calling/returning a function. Otherwise multiple use of an inline function may result in a larger code size. Only testing will prove the result, and then tests may be rubbish as they may not represent what happens in real use of the code.

Below is what I would do. It will do the maths using the largest type provided so there is no need to specify the value in pointy brackets. The code is more complex, however it makes it easier for the end user.

`template< bool V, typename T, typename U > struct Select{ typedef T Result; };`

template< typename T, typename U > struct Select< false, T, U >{ typedef U Result; };

template< typename T, typename U > struct LargerType{

typedef typename Select< sizeof( U ) < sizeof( T ), T, U >::Result Result;

};

template< typename T, typename U, typename V, typename X, typename Y >

T map( const T &x, const U &imin, const V &imax, const X &omin, const Y &omax ) throw()

{

typedef typename LargerType< typename LargerType< typename LargerType< T, U >::Result, typename LargerType< V, X >::Result >::Result, Y >::Result cll;

return (cll)(x - imin) * (omax - omin) / (imax - imin) + omin;

}

The C++11 version can be a little more efficient (specific cases) using move semantics:

`template< typename T, typename U, typename V, typename X, typename Y > `

auto map( const T &x, U &&imin, V &&imax, X &&omin, Y &&omax ) -> T

{

typedef typename LargerType< typename LargerType< typename LargerType< T, U >::Result, typename LargerType< V, X >::Result >::Result, Y >::Result cll;

return (cll)(x - imin) * (omax - omin) / (imax - imin) + omin;

}