Reputation: 153889
Given the following code:
#include <vector>
template<class C1, class C2, class Op>
std::vector<typename Op::result_type>
f(Op op, const C1& src1, const C2& src2)
{
}
template<class It, class Op>
std::vector<typename Op::result_type> g(Op op, It begin, It end)
{
}
template<class It1, class It2, class Op>
std::vector<typename Op::result_type> g(Op op, It1 left_begin, It1 left_end, It2 right_begin)
{
return std::vector<typename Op::result_type>();
}
struct ToS
{
typedef double result_type;
double operator() (long , double ) const { return 0.0; }
};
std::vector<double> h(std::vector<long> const& vl, std::vector<double> const& vd)
{
return g(ToS(), vl.begin(), vl.end(), vd.begin());
}
When compiled with Visual C++ 2010 (SP1), I get the following errors:
1>VC10Error.cpp(30): error C2893: Failed to specialize function template 'std::vector<Op::result_type> g(Op,It1,It1,It2)'
1> With the following template arguments:
1> 'std::_Vector_const_iterator<_Myvec>'
1> with
1> [
1> _Myvec=std::_Vector_val<long,std::allocator<long>>
1> ]
1> 'std::_Vector_const_iterator<_Myvec>'
1> with
1> [
1> _Myvec=std::_Vector_val<double,std::allocator<double>>
1> ]
1> 'ToS'
1>VC10Error.cpp(30): error C2780: 'std::vector<Op::result_type> g(Op,It,It)' : expects 3 arguments - 4 provided
1> VC10Error.cpp(12) : see declaration of 'g'
I don't understand them. First, of course, the error message basically
sums up as "There's something wrong here, but we won't tell you what'.
And secondly, I don't find anything wrong; nor does g++ (version 4.4.2).
Other interesting symptoms: if you add a using std::vector;
after the
include, and delete all of the std::
, it works—I would have
thought that that should have no effect. And if you delete either the
function f
(which really isn't used anywhere) or the first version of
function g
, it also works.
So am I crazy, or is VC10 really not yet production-ready?
EDITED: Just to add: if it is a bug in the compiler, how do I reliably work around it?
Upvotes: 13
Views: 947
Reputation: 12764
Indeed it appears a bug in the compiler.
In your simplified example, the issue goes away if the two versions of g()
exchange places, or if f()
is commented out, or f()
exchange places with g<It,Op>(Op, It, It)
.
Upvotes: 3
Reputation: 69958
It works fine with g++ compiler. So it's possible that VC++ is not able to parse through it properly (may be a bug in that case). Your code is proper.
Upvotes: 0