| |
comp.lang.c++ |
>> Brian is not writing a Swap function. >> He wants a template that expands one way if its argument has a given >> There probably is no way to do what he wants without passing some >> Foo<MyAclass, policyWithMethod>(); >> Now the question becomes this: How do you make the template #include <iostream> template<class T> struct has_member_Swap; template<class R, class C> class has_member_Swap<R C::*> { struct B { template<class T> class is_class {
> "Phlip" <phlip...@yahoo.com> wrote in message
> news:b4jqoi$dnj@dispatch.concentric.net...
>> method, and another way if it does not. I honestly can't tell if you
>> read the same post as I.
>> kind of extra template into the main template. So, if he needed to
>> Foo instead of Swap, he'd write one of:
>> Foo<MyBclass, policyWithoutMethod>();
>> automatically select one or the other policy? The answer is you
>> can't.
private:
template<R C::*> struct helper;
template<class T> static char check(helper<&T::Swap>*);
template<class T> static char (& check(...))[2];
public:
enum { value = sizeof(check<C>(0)) == 1 };
void Swap(B&) throw();
std::cout
<< has_member_Swap<void (A::*)(A&) throw()>::value << '\n';
<< has_member_Swap<void (B::*)(B&) throw()>::value << &std::endl;
return 0;
private:
template<class U> static char check(int U::*);
template<class U> static char (& check(...))[2];
public:
enum { value = sizeof(check<T>(0)) == 1 };
Paul Mensonides