I'm trying to create an overloaded method, where both are templated. One takes 4 arguments, and one takes 5. However I get an error along the lines of
Error C2780 ... OutOfPlaceReturn ... : expects 4 arguments - 5 provided.
... A bunch of template parameters ...
See declaration of ' ... ::OutOfPlaceReturn'
which references the line of the 4 argument method definition
In this case I'm trying to call the overload with 5 arguments, so I don't understand why the compiler thinks I want to call the function which only takes 4 arguments.
The full context is too complex to give the full code example, but suffice it to say this all takes place inside of a class template, which has lots of local typedef
s, including samp_type
, const_samp
, samp_vec
, etc. These are all either typedefs of a template argument which holds a POD type, or a std::array
of one of these POD types
typedef int_fast16_t fast_int;
typedef typename std::add_const< fast_int >::type const_fast_int;
typedef samp_type (*func_type)(const_samp, const_samp);
template<func_type operation, const_fast_int strideA, const_fast_int strideB, const_fast_int strideOut>
static inline samp_vec OutOfPlaceReturn(const std::array<samp_type, strideA * vectorLen> &a,
const_fast_int strideA,
const std::array<samp_type, strideB * vectorLen> &b,
const_fast_int strideB,
const_fast_int strideOut)
{
std::array<samp_type, vectorLen * strideOut> output;
for(fast_int i = 0; i < vectorLen; ++i)
output[i * strideOut] = operation(a[i * strideA], b[i * strideB]);
return output;
}
template<func_type operation, const_fast_int strideA, const_fast_int strideOut>
static inline samp_vec OutOfPlaceReturn(const std::array<samp_type, strideA * vectorLen> &a,
const_fast_int strideA,
const_samp_ref b,
const_fast_int strideOut)
{
std::array<samp_type, vectorLen * strideOut> output;
for(fast_int i = 0; i < vectorLen; ++i)
output[i * strideOut] = operation(a[i * strideA], b);
return output;
}
If I understand correctly, when calling a template function, you don't need to provide the template parameters which the compiler can deduce through function arguments, so the call looks like this
static samp_vec subtract(const_vec_ref a, const_fast_int strideA, const_vec_ref b, const_fast_int strideB, const_fast_int strideOut)
{ return OutOfPlaceReturn<MathClass::subtract>(a, strideA, b, strideB, strideOut); }
So, is there something wrong with the way I'm calling these template methods? Is there something wrong with the way I'm expecting the compiler to resolve overloads?
Edit
I'm using VS2010. So far it's been pretty good with templates and C++11 data-types. Not sure if my compiler is acting sub-par