Boost logo

Boost :

Subject: Re: [boost] [guidelines] why template errors suck
From: David Abrahams (dave_at_[hidden])
Date: 2010-09-27 13:18:37


On Sep 27, 2010, at 12:38 PM, Robert Ramey wrote:
>
> David Abrahams wrote:
>> At Mon, 27 Sep 2010 11:40:31 +0800,
>> Dean Michael Berris wrote:
>>>
>>> The way concepts are done now is to define the syntactic requirements
>>> (not so much the semantics)
>>
>> I think I know what you mean, but I wouldn't say it that way.
>> Notwithstanding the fact that the compiler can never verify semantic
>> conformance to a concept, the semantics are a required part of any
>> concept definition. If your concept omits semantics, it's broken.
>
> Hmmm - my dabbling in concepts led me to the opposite conclusion.
>
> That is, an attempt to capture semantics in concepts is doomed
> to fail.

Semantics are part of what makes up a concept, by definition.

> It's the implementation which defines the semantics while
> the concepts only can check the syntax.

Yes. You won't get automated semantic validation, period, which is one reason I was very uneasy about the "axioms" feature in the later concept proposals. That doesn't mean semantics aren't a part of concepts, just that maybe they shouldn't be part of the language feature (or library emulation thereof).

> The idea that concepts
> could somehow help in clarifying the semantics made it much
> harder to grasp what the concept (of concepts) was about.

No offense, but you cannot possibly be grasping the "concept (of concepts)" now if you are ignoring semantics. If you got the understanding you have now by omitting semantics, it's a mis-understanding.

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.

> Of
> course the nomenclature doesn't help any either.

Sorry, I don't know what you're talking about here.

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

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