VC8 function template ambiguity problems

Dear All, I was hoping that VC8 would finally fix up problems with it's ambiguity resolution system for function template arguments. Sadly the current beta version as used for Boost regression tests still has problems. See http://engineering.meta-comm.com/boost-regression/CVS-HEAD/developer/output/... for a failure in Boost::uBLAS. The same problem is not shown for previous VC compilers as the offending tests are simply disabled. The problem can easily be exemplified with the follow code which still fails on VC-8 struct range { }; template<class V> struct vector_range { typedef range range_type; }; template<class V> struct vector_slice { typedef range range_type; }; template<class V> void simple (V &data, const range &r) {} template<class V> void simple (vector_slice<V> &data, const range &r) {} template<class V> void hard (V &data, const typename vector_range<V>::range_type &r) {} template<class V> void hard (vector_slice<V> &data, const typename vector_slice<V>::range_type &r) {} main () { vector_slice<int> vs; simple (vs, range() ); hard (vs, range() ); } There are no problems with the functions 'simple'. It thinks the functions 'hard' are ambiguous despite the fact that the first parameter is more specialised in the second version. It seems to be disturbed by template parameter dependence of the second parameter. Anyone know of a workaround? For those that know a little more about MS compiler, or have support for it. Is the current beta of VC-8 close to the final version or is it likely that i such deeply rooted template problems are going be fixed? Michael -- ___________________________________ Michael Stevens Systems Engineering 34128 Kassel, Germany Navigation Systems, Estimation and Bayesian Filtering http://bayesclasses.sf.net ___________________________________

From: Michael Stevens <mail@michael-stevens.de>
[snip]
template<class V> void hard (V &data, const typename vector_range<V>::range_type &r) {} template<class V> void hard (vector_slice<V> &data, const typename vector_slice<V>::range_type &r) {}
main () { vector_slice<int> vs; simple (vs, range() ); hard (vs, range() ); }
There are no problems with the functions 'simple'. It thinks the functions 'hard' are ambiguous despite the fact that the first parameter is more specialised in the second version. It seems to be disturbed by template parameter dependence of the second parameter.
Anyone know of a workaround?
What about shifting "const" around? template <class V> void hard(V &data, typename vector_range<V>::range_type const &r) {} template <class V> void hard(vector_slice<V> &data, typename vector_slice<V>::range_type const &r) {} What about putting them in a class template? Then you could introduce typedefs to simplify the expressions the compiler must grok. (WARNING: No compiler has had opportunity to comment on the following code.) template <class V> struct hard_helper { typedef typename vector_range<V>::range_type range_type; void apply(V &data, range_type const &r) {} }; template <class V> struct hard_helper<vector_slice<V> > { typedef typename vector_slice<V>::range_type range_type; void apply(V &data, range_type const &r) {} }; template <class V, class R> inline void hard(V &data, R const &r) { hard_helper<V>::apply(data, r); } -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;

Michael Stevens wrote: [...]
template<class V> void hard (V &data, const typename vector_range<V>::range_type &r) {} template<class V> void hard (vector_slice<V> &data, const typename vector_slice<V>::range_type &r) {}
[...]
It thinks the functions 'hard' are ambiguous despite the fact that the first parameter is more specialised in the second version.
The functions do seem ambiguous to me. I see no partial ordering between them.
participants (3)
-
Michael Stevens
-
Peter Dimov
-
Rob Stewart