|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-09-20 08:22:02
Terje Slettebø <tslettebo_at_[hidden]> writes:
>> enable_if doesn't always improve error messages. Sometimes you get a
>> long list of candidate functions when what you really wanted was a
>> message from inside just one of the overloads that indicates how
>> concept conformance was violated.
> How can you get a list of candidate functions, if enable_if excludes them
> from the overload set? Could you give a code example?
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
template <class T>
typename boost::enable_if<boost::is_same<T,int>,int>::type
f(T);
template <class T>
typename boost::enable_if<boost::is_same<T,long*>,int>::type
f(T);
int main()
{
f("foo");
}
CWPro9:
### mwcc Compiler:
# File: foo.cpp
# ----------------
# 14: f("foo");
# Error: ^
# function call 'f({lval} const char[4])' does not match
# 'f<...>(__T0)'
# 'f<...>(__T0)'
VC7.1:
foo.cpp
foo.cpp(14) : error C2893: Failed to specialize function template 'boost::enable_if<
boost::is_same<T, long *>, int
>::type f(T)'
With the following template arguments:
'const char *'
foo.cpp(14) : error C2893: Failed to specialize function template 'boost::enable_if<
boost::is_same<T, int>, int
>::type f(T)'
With the following template arguments:
'const char *'
And even when there's no list as with GCC, "no match" is usually
less-useful than "here's what's wrong with the argument."
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk