C++ parameter pack, constrained to have instances of a single type?

With std::common_type, this is straightforward:

template <class... Args, class = std::common_type_t<Args...>>
void foo(Args &&... args) {

}

This will only be guaranteed to be SFINAE-friendly from C++17 onwards, though. Clang and GCC both implement it that way already.

Leave a Comment