Boost logo

Boost :

Subject: Re: [boost] [guidelines] why template errors suck
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2010-09-28 04:33:01


On 27/09/2010 23:01, David Abrahams wrote:
> At Mon, 27 Sep 2010 22:01:09 +0100,
> Mathias Gaunard wrote:
>>
>> On 27/09/2010 17:56, David Abrahams wrote:
>>
>>> 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 don't see how a set of statements is much different from a set of
>> expressions, except that statements don't have nice properties from a
>> meta-programming point of view.
>
> No comment.
>
> do-the-exercise-ly y'rs,
>

I've done it and there was no particular problem. I just need to check
the argument are input iterators and an unary function object taking the
same value as the iterator value type and returning a boolean.
(of course, by taking a particular value, I really mean taking something
that can be converted from that particular value, and by returning a
particular value I mean returning a type convertible to that value, but
all of those implicit conversions are taken care of automatically by
expressions)

The concept definitions of iterators and function objects are already
defined in terms of valid expressions anyway, each having particular
semantics.

Are you maybe hinting at a trick to properly ensure input iterators and
not just forward ones?

Also, I don't think replacing statements by expressions means we should
get rid of archetypes at all. They're still required if you want to
actually instantiate the template and test the code, rather than just
test that the arguments match what you expect.
Checking the arguments match what you expect is the important bit for
good error messages and validation, while archetypes are really useful
for development to check your code and your requirements are consistent
by ensuring it works with the minimal amount of requirements.

All in all, ConceptCheck isn't so bad: we just need to replace the main
body of statements by a compile-time itereable and manipulable list of
expressions.


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