Boost logo

Boost :

Subject: Re: [boost] [contract] concept error messages
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2012-10-07 16:08:55

On Sun, Oct 7, 2012 at 3:51 PM, Lorenzo Caminiti <lorcaminiti_at_[hidden]>wrote:

> I agree, this type of overloading is a reason for having requires,
> enable_if will not suffice. Is there any other reason?

With requires (at least the C++0x version of it), you will get a
compile-time error if, from within the body of the template you are
writing, you attempt to perform an operation that was not specified as a
requirement in the requires clause. This error will be given to the user at
the time they write the algorithm (even if it is never called) and so the
writer of the algorithm can't accidentally assume functionality that may or
not be supported by the template's arguments. With enable_if, you are just
doing parameter checking, meaning that the body of your function cannot be
checked in this manner for validity at the time you write your algorithm.
Instead, if the writer of the algorithm makes a mistake, the user of the
algorithm will get a messy compile-error inside of the algorithm's body (or
the body of something that it calls) at the moment it is instantiated.

-Matt Calabrese

Boost list run by bdawes at, gregod at, cpdaniel at, john at