Boost logo

Boost Users :

Subject: Re: [Boost-users] Question about enable_if / disable_if
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-05-23 06:55:13


Hi!

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) {...}

template<typename T>
void f(const std::string&, typename enable_if<boost::is_enum<T>, T>::type t)
{...}

On Sat, May 23, 2009 at 7:19 AM, Zachary Turner <divisortheory_at_[hidden]>wrote:

> Suppose I have a template function
>
> template<typename T> void f(const std::string&, T);
>
> which I want there to be a couple of different variants of.
>
> Version 1 - Enabled if and only if boost::is_same<T, bool>
> Version 2 - Enabled if and only if boost::is_same<T, foo> (foo is a class)
> Version 3 - Enabled if and only if boost::is_enum<T>
> Version 4 - Otherwise
>
> Is there an easy way to express this? It seems I run into a bunch of
> overload ambiguity problems. I'm sure I can get around this by adding to
> every version the negation of all the other conditions, but this seems
> unnecessarily complicated.
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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