Boost logo

Boost :

Subject: Re: [boost] enable_if and non-template member functions?
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2011-08-12 17:14:24


On Fri, 12 Aug 2011, Mostafa wrote:

> On Fri, 12 Aug 2011 02:31:10 -0700, John Maddock <boost.regex_at_[hidden]>
> wrote:
>
>>> 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.
>
> In case of no-parameter functions or operators, what's wrong with:
>
> template <class U>
> struct T
> {
> void f()
> {
> f_impl(<static_cast<void *>(0));
> }
>
> private:
> template <class T>
> typename enable_if<
> mpl::and_<
> is_convertible<T, void *>,
> some_condition_on<U>
> >::type
> f_impl(T)
> { .... }
> };

In that case, f would not be covered by SFINAE, since it is not a
template. Calls to f would fail because of the lack of f_impl, but that
would be done after overload resolution.

-- Jeremiah Willcock


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