Re: Why the following SFINAE test does not work?
Am 11.11.2010 18:30, schrieb Andy Venikov:
On 11/11/2010 7:59 AM, Michael Doubez wrote:
<snip>
I don't understand your answer. I have read the thread you mention but
in this case, the program is not ill formed. It is just that the
relevant overloads are not matched.
You're right, I think I jumped the gun. When I was playing around with
OP's program, at some point I got a compile error about using operator&
in a constexpr context. Of course by that time I've modified the
original code so that an address of a variable was being taken and
forgot about that. Using an address of a member should and is allowed to
be used as a non-type template argument. My bad.
It could even be an address of a variable of static storage duration
or any other constant expression (in C++0x), e.g. the following example in
namespace scope should also be well-formed:
template<class U, U u>
struct coerce {};
int i;
template<class U, int* P>
int test(U*, coerce<U*, P>* = 0);
template<class U, int* P>
void test(...);
typedef decltype(test<int, &i>(0)) type;
static_assert(sizeof(type) > 0, "Ouch");
Now, back to the original problem. Here's a piece of code that pinpoints
the issue:
struct with_apply
{
template <unsigned>
void apply(const double&);
};
auto p = &with_apply::apply<0>;
This should be well-formed, and the OP's example should be so as well.
This produces an error that says that the compiler couldn't chose the
right apply among the overloads.
IMO this is a compiler-defect.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]