Boost logo

Boost :

Subject: Re: [boost] enable_if and non-template member functions?
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-08-12 05:31:10


>From your description, I think I've done exactly this. E.g.

--8<---------------cut here---------------start------------->8---
template <class U>
struct X
{
     // member function void f(int) becomes something like:
     template <class T>
     typename enable_if<
        mpl::and_<
            is_convertible<T,int>
          , some_condition_on<U>
>
>::type
     f(T x_)
     { int x = x_; ... }
};
--8<---------------cut here---------------end--------------->8---

That works as long as the function has at least one parameter that can be
turned into a template, but I have some cases that are operators or else
have no parameters.

So for now I think I'll stick to the old "this member can't be instantiated
unless T models X". It prevents explicit instantiation, but never mind I
guess...

BTW, it would be great if all these techniques could be added to the
enable_if docs.

Cheers, John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk