|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-07-09 16:22:15
"Peter Dimov" <pdimov_at_[hidden]> writes:
> David Abrahams wrote:
>> Jaakko Jarvi <jajarvi_at_[hidden]> writes:
>>
>>> Where we've used enable_if, it has been very common that the
>>> condition is not just a single traits lookup, but rather a logical
>>> expression, e.g.:
>>>
>>> template <class T, class U>
>>> typename enable_if<is_matrix<T>::value &&
>>> is_vector<U>::value,...>::type operator*(const T& t, const U& u);
>>>
>>> So definitely, this version of enable_if is needed.
>>
>> really?
>>
>> template <class T, class U>
>> typename enable_if<mpl::and<is_matrix<T>, is_vector<U>
>> >,...>::type operator*(const T& t, const U& u);
>>
>> looks better to me.
>
> Sorry, no. If you deny me a non-broken enable_if
Calling the version I want "broken" is quite extreme, and I ask you
to justify it.
> I'll just write one myself. I am not going to uglify my expressions
Clearly the ugliness is a matter of opinion. I think the usage with
mpl::and_ is much prettier.
> for no good reason.
That aside, there are good reasons to do it my way:
* Almost always terser
* Works with more compilers
* Results in fewer template instantiations (mpl::and_<...> does
short-circuit instantiation)
* enable_if<_1, _2> is a valid lambda expression
What am I forgetting? I'm sure there are a few others.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk