Boost logo

Boost Users :

Subject: Re: [Boost-users] Question about enable_if / disable_if
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2009-05-26 11:03:32


On Sat, May 23, 2009 at 5:55 AM, Ovanes Markarian
<om_boost_at_[hidden]> wrote:
> Why do you need an enable_if if you exactly know the type T? In that case
> you can use the temmplate specialization.
>
> template<>
> void f(const std::string&, bool) {...}
>
> template<>
> void f(const std::string&, foo) {...}

Why template specialization instead of regular functions?

Would that somehow force some types to go to the bool or foo overload
via an implicit conversion rather than thru the generic catch all
template (version 4)? (I've found "the resolution mechanism for a
function call will always prefer a normal c++ function in case of
equals. But if the best match is with the template function, it will
prefer the templates" that seem to say no, but that's hardly an
authoritative source though)

Obviously I'm only vaguely aware of the exact function resolution
rules in this case, so if anyone can shed some more light on this
particular example I'd appreciate. Thanks, --DD

> template<typename T>
> void f(const std::string&, typename enable_if<boost::is_enum<T>, T>::type 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