
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