Boost logo

Boost :

Subject: Re: [boost] [guidelines] why template errors suck
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2010-09-27 18:27:36

On 27/09/10 17:56, David Abrahams wrote:
> On Sep 27, 2010, at 9:51 AM, Andrew Sutton wrote:
>>>> * Write down the find_if algorithm in a natural way
>>>> * write down the valid expressions implied by that algorithm
>>>> * now re-check the algorithm against the valid expressions
>>> So, no takers? :-)
>> I'm not sure I fully understand the problem.
> Of course not; you didn't try it! ;-)
>> Surely, you can use the Concept_check library to describe
>> constraints for the find_if algorithm, and the Concept_check
>> library internally validates those constraints against expressions
>> expected to be valid. To me, that would imply that valid
>> expressions can be used to describe constraints.
>> Am I missing something?
> Among other things, you're missing the other half of concept
> checking: checking algorithm bodies against constraints (which is
> done in the Concept_check library by using archetypes).
> P.S. I'm not claiming concepts can't be described via valid
> expressions; I'm claiming it's the wrong approach, for reasons that
> should become evident to anyone who *actually does the exercise*.

I did do the exercise, so SPOILERS ahead for those who have not.

I'm still not sure what your point is. I conjecture that the issue to
which you were trying to draw attention was something to do with
operator! and bool conversions.

In particular I note that the libstdc++ implementation of find_if uses
!bool(__pred(*__first)) rather than simply !__pred(*__first), which
suggests this distinction is (at least potentially) important in
practice. Presumably the concept modelled by the predicate merely
asserts that its return type is convertible to bool (certainly that's
all I had in mind), and in principle !__pred(*__first) is undefined
behaviour with respect to the concept.

Is your point that an archetype based on valid expressions would fail to
detect the flaw in the naive implementation of find_if, but that an
archetype based on member definitions would catch it?

John Bytheway

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