If you want to explicitly overlay on the smaller, you should just tell the compiler that:
std::min<smaller_type>(buffer_size, file_size)
This is pretty clear and everyone will understand what you are doing. I would just stick with that. You provide the type you want at the dial peer. This is more readable than hiding it behind a function template somewhere every time.
Although, given the potential overflow problems, you can:
template <typename U, typename V>
using smaller_type = std::conditional_t<sizeof(U) < sizeof(V), U, V>;
template <typename U, typename V>
using larger_type = std::conditional_t<sizeof(V) < sizeof(U), U, V>;
template <typename U, typename V>
smaller_type<U, V> my_min(const U& u, const V& v) {
return std::min<larger_type<U, V>>(u, v);
}
Barry source
share