Like this, also, passing a value to force a return type is not really a nice way to do it, use the template argument instead :
#include <iostream>
#include <cmath>
template <typename Ret, typename T>
Ret round( T val ) {
return static_cast<Ret>(
( val >= 0 ) ?
std::floor( val + (T) ( .5 ) ) :
std::ceil( val - (T) ( .5 ) )
);
}
template <typename T>
T round( T val ) {
return round<T,T>( val );
}
auto a = round<int>( 5.5 ); // int a = 6
auto b = round( 5.5 ); // double b = 6.0
static_assert( std::is_same<decltype(a), int>::value, "a must be int" );
static_assert( std::is_same<decltype(b), double>::value, "b must be double" );
int main() {
std::cout << a << " " << b;
}