Boost logo

Boost Users :

Subject: Re: [Boost-users] enable_if catch all?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-07-19 17:22:18


Zachary Turner wrote:
> Supposing I have 4 or 5 mutually exclusive overloads of a function
> using enable_if as a function parameter with a default argument, is
> there any way for me to provide an additional version of this function
> that handles every other case, without manually combining all the
> previous cases and using another enable_if?
>
> For example:
>
> template<class T>
> void foo(typename enable_if<condition1>::type* dummy=0) {}
>
> template<class T>
> void foo(typename enable_if<condition2>::type* dummy=0) {}
>
> template<class T>
> void foo(typename enable_if<condition3>::type* dummy=0) {}
>
> template<class T>
> void foo(typename enable_if<condition4>::type* dummy=0) {}
>
> template<class T>
> void foo()
> {
> //default instantiation that gets invoked if and only if all of the
> other overloads fail
> }

template<class T>
void foo(...)
{
     //default instantiation that gets invoked if and only if all of the
> other overloads fail
}

Note, however, it will only work if you call foo<T>(0) and not if you
call foo<T>().


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net