Boost logo

Boost :

Subject: Re: [boost] [guidelines] why template errors suck
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-09-27 15:18:47


David Abrahams wrote:
> On Sep 27, 2010, at 12:38 PM, Robert Ramey wrote:
>>
>> David Abrahams wrote:

> A simple demonstration of why semantics are essential to concepts:
> take std::sort for example:
>
> template <class RandomAccessIterator It, class StrictWeakOrdering>
> void sort(It start, It end, StrictWeakOrdering Cmp);
>
> It is impossible to write sort (or document what it does) without the
> assumption that StrictWeakOrdering follows certain semantic laws
> (described at http://cpp-next.com/archive/2010/02/order-i-say/).
> It's not just a binary function object to which you can pass It's
> value_type and whose return value is convertible to bool. Those are
> the syntactic requirements, but there are lots of such functions that
> won't result in a sorted sequence.

My experience was in trying to apply this to the serialization library.
My example was

ar << t;

where t is of serializable type T and ar is an instance of an Archive class

The "archive concept" would admit a wide variety of semantics.
The archive classes included in the library include code for deep
copy/recover of pointers to polymorphic classes. But in another
context, such as one which only displays data for debugging,
one might implement this functionality as just a top level display
so that he can make a header only version. So here one has two useful
widely varying implementation symantics with exactly the same
syntax requirements. Is it wrong to use concepts here? Is
it wrong to make such a library? Is is wrong, to "hijack"
a types concepts for unintended uses?

I concluded that it not really possible to specify symantics
and any formal or rigorous way without actually writing the code
itself.. It doesn't make the idea of validation of template parameters
useless,
it just puts a limit of one can realistically expect from it.

>> Of
>> course the nomenclature doesn't help any either.
>
> Sorry, I don't know what you're talking about here.

I was referring to the usage of the word "concept" in this context. I
found this to be very misleading and not at all descriptive of the
the function of "checking template parameters at compile time"

Robert Ramey


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