example:
<code>#include <cstdio>
class Dummy {};
template<typename T>
class IsDummy { public: enum { Value = 0, }; };
template<>
class IsDummy<Dummy> { public: enum { Value = 1, }; };
template<typename T, int isDummy = IsDummy<T>::Value>
class Wrapper { };
template<typename T>
class Wrapper<T, 1> {
public:
typedef T Value;
};
static void func(Dummy *) {}
static void func(const char *) {}
class Object0 {
public:
template<typename T>
operator T *(void) const {return NULL;}
};
class Object1 {
public:
template<typename T>
operator typename Wrapper<T>::Value *(void) const {return NULL;}
};
int main(int argc, char **argv)
{
Object0 o0;
func(o0); // <= ambiguous
Object1 o1;
func(o1); // <= no matching function
return 0;
}
</code>
<code>#include <cstdio>
class Dummy {};
template<typename T>
class IsDummy { public: enum { Value = 0, }; };
template<>
class IsDummy<Dummy> { public: enum { Value = 1, }; };
template<typename T, int isDummy = IsDummy<T>::Value>
class Wrapper { };
template<typename T>
class Wrapper<T, 1> {
public:
typedef T Value;
};
static void func(Dummy *) {}
static void func(const char *) {}
class Object0 {
public:
template<typename T>
operator T *(void) const {return NULL;}
};
class Object1 {
public:
template<typename T>
operator typename Wrapper<T>::Value *(void) const {return NULL;}
};
int main(int argc, char **argv)
{
Object0 o0;
func(o0); // <= ambiguous
Object1 o1;
func(o1); // <= no matching function
return 0;
}
</code>
#include <cstdio>
class Dummy {};
template<typename T>
class IsDummy { public: enum { Value = 0, }; };
template<>
class IsDummy<Dummy> { public: enum { Value = 1, }; };
template<typename T, int isDummy = IsDummy<T>::Value>
class Wrapper { };
template<typename T>
class Wrapper<T, 1> {
public:
typedef T Value;
};
static void func(Dummy *) {}
static void func(const char *) {}
class Object0 {
public:
template<typename T>
operator T *(void) const {return NULL;}
};
class Object1 {
public:
template<typename T>
operator typename Wrapper<T>::Value *(void) const {return NULL;}
};
int main(int argc, char **argv)
{
Object0 o0;
func(o0); // <= ambiguous
Object1 o1;
func(o1); // <= no matching function
return 0;
}
what i want to do:
- make
func(o0)
andfunc(o1)
matchesfunc(Dummy *)
only (and any further class specialized byIsDummy<>
), but not forfunc(const char *)
- compatible for cpp03 (which does not support partial specialization for functions (
operator T()
function) )
what happens:
func(o0)
would causeambiguous
func(o1)
would causeno matching function
2