Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-07-09 16:51:55


David Abrahams wrote:
> "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 didn't say "the version you want is broken." What I said roughly
translates to: "an enable_if facility that only includes the version you
want may be perceived as broken by certain audiences which I decided to
represent in this discussion 'cause I felt like it."

>> I'll just write one myself. I am not going to uglify my expressions
>
> Clearly the ugliness is a matter of opinion.

Precisely.

> I think the usage with mpl::and_ is much prettier.

Sure, in a way. Some might say Python is prettier than C++. Others may find
Lisp prettier than both. The point is that in C++, the C++ expression syntax
wins beauty contests by default.

>> for no good reason.
>
> That aside, there are good reasons to do it my way:
>
> * Almost always terser

OK.

> * Works with more compilers

The compilers that can do SFINAE well enough for enable_if should be able to
handle && in integral constant expressions, no?

> * Results in fewer template instantiations (mpl::and_<...> does
> short-circuit instantiation)

Interesting point. I didn't think of it.

> * enable_if<_1, _2> is a valid lambda expression

Doesn't matter, unless I'm missing something. I'm not saying that an mpl
friendly enable_if should not be included. I'm saying that forcing mpl on
people is not necessarily a good idea.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk