|
Boost Users : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2004-06-12 17:24:25
On Jun 12, 2004, at 5:20 PM, Agoston Bejo wrote:
> Hi,
> I understand that by using enable_if the following way:
>
> template <class T>
> T foo(T t, typename enable_if<boost::is_arithmetic<T> >::type* dummy =
> 0);
>
> I can include/exclude the appropriate function overloads.
> When I write:
>
> template<class T>
> T foo(T t, typename enable_if<[condition1]>::type* dummy = 0,
> typename enable_if<[condition2]>::type* dummy = 0);
>
> Does this mean an AND-relationship between condition1 and condition2?
> (So
> that a particular overload is enabled if and only if both conditions
> evaluate to true?)
Yes, it does mean "and". But it is a cryptic way to do it. Instead
consider:
template<class T>
T foo(T t, typename enable_if<condition1 && condition2>::type* dummy =
0);
Also, no need for the dummy name:
template<class T>
T foo(T t, typename enable_if<condition1 && condition2>::type* = 0);
And you might prefer to place the condition on the return type for
readability purposes:
template <class T>
typename enable_if
<
condition1 && condition2,
T
>::type
foo(T t);
-Howard
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