Subject: Re: [boost] [parameter] type predicates vs. concepts
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-12-15 11:26:24
On Thu, Dec 15, 2011 at 7:18 AM, Dave Abrahams <dave_at_[hidden]> wrote:
> on Sun Dec 04 2011, Lorenzo Caminiti <lorcaminiti-AT-gmail.com> wrote:
>> Hello all,
>> What's the difference between using a Boost.Parameter type predicate
>> and using a concept?
>> I think parameter type predicates are unary metafunctions used to
>> resolve the function call, concepts are asserted on the type after the
>> call has been resolved... Is there more?
> Overload ordering on concepts, but I see you're not talking about real
> concepts, just BCCL concepts.
Yes, I'm referring to Boost.Concept-- even with C++11 that's all we'll
>> Can I always do with type predicates what I can do with concepts?
> No, type predicates are required not to cause a compilation error, so
> there are limits to what they can detect in C++03 (e.g. copyability).
> Concept checks are specifically used to cause compilation errors.
>> Is there ever a reason to use/need both?
>> For example here has_equal_to is the type predicate while
>> DefautlConstructible is the concept. Could/should I have used
>> has_[...]_default_constructor in and_ the type predicate instead of
>> the DefaultConstructible concept?
> I think unless the compiler has implemented a special intrinsic, in
> C++03 has_[...]_default_constructor is at best an imperfect emulation.
1) As you pointed out, there are conditions we can program with
concepts but not with type predicates (imperfect type traits, etc). Is
the opposite true: Can I always program a concept if I can program a
type predicate? I'd think so...
2) As pointed out by Jeff, another difference is in the error
reporting-- concept failures might be more informative than a SFINAE
saying "can't resolve an overloaded function call" (because it doesn't
say which type failed which requirement).
Any other difference? Any "theoretical" difference?
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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk