Boost logo

Boost :

Subject: Re: [boost] [parameter] type predicates vs. concepts
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-12-17 17:02:18


on Fri Dec 16 2011, "Jeffrey Lee Hellrung, Jr." <jeffrey.hellrung-AT-gmail.com> wrote:

> On Thu, Dec 15, 2011 at 8:26 AM, Lorenzo Caminiti <lorcaminiti_at_[hidden]>wrote:
> [...]
>
>> I'm asking because Boost.Contract will support both type predicates
>> and concepts so I need to tell the users why they can use both, when
>> to use concepts, and when to use type predicates. Actually,
>> Boost.Parameter also supports both because it can be used together
>> with Boost.Concept so IMO it'd be nice to add the same explanation to
>> Boost.Parameter as well.
>>
>
> I don't think Boost.Contract nor Boost.Parameter is special in this regard.
> The guideline I follow is: use type predicates only to differentiate
> between overloads via SFINAE; otherwise, use concept assertions, as they
> typically provide more informative error messages and don't complicate the
> function signature.

I mostly agree, but there are a few exceptions to that rule. One is
when you're writing conversion operators, constructors, or other
operations with broadly-understood semantics: if you don't use SFINAE to
take them out of contention when they don't apply, then other people
using traits (usually relying on SFINAE tricks themselves) will get the
wrong answer for, e.g., is_convertible<T,U>, has_addition<T>, etc.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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