Aaron Graham wrote:
template <typename T, typename U, typename V>
void foo(const T& t, const U& u, const V& v);
Now, to provide an equivalent solution for this one, I would need to
define 7 more overloaded functions.
You can do it with a single forwarding function like this:
#include <cstddef> // for size_t
template <typename T>
struct Param { typedef T type; };
template <typename T, std::size_t N>
struct Param<T[N]> { typedef const T* type; };
template <typename T, typename U, typename V>
void foo_impl(const T& t, const U& u, const V& v)
{
}
template <typename T, typename U, typename V>
void foo(const T& t, const U& u, const V& v)
{
foo_impl(
static_cast<typename Param<T>::type>(t),
static_cast<typename Param<U>::type>(u),
static_cast<typename Param<V>::type>(v) );
}
Note that if any of foo's parameters need to be non-const-qualified
references (i.e. so that const-ness is deduced from the parameter
coming in), a little more work is needed.
[ comp.lang.c++.moderated. First time posters: Do this! ]