Boost logo

Boost :

Subject: Re: [boost] Provisional Boost.Generic and Boost.Auto_Function (concepts without concepts)
From: Dave Abrahams (dave_at_[hidden])
Date: 2010-12-15 14:19:43

At Tue, 14 Dec 2010 07:41:17 -0500,
Matt Calabrese wrote:
> On Tue, Dec 14, 2010 at 7:11 AM, Matt Calabrese <rivorus_at_[hidden]> wrote:
> > Anyway, I've said more than I wanted to right now. I didn't expect this
> > thread to be bumped -- I was hoping to post a new thread about all of this
> > once everything was polished and up in the sandbox.
> >
> Actually, since this thread has started going again, I've hit some
> complicated issues regarding concept maps that I'd hope someone could help
> out with. In particular, there is one very troubling situation I've
> encountered. Imagine three concept types: a "base" concept,

concrete code helps:

  concept Base<typename T>
      T operator*(T, T);

> a "left" concept
> which is a refinement of "base", and a "right" concept, which is also a
> refinement of "base".

  concept Left<typename T> : Base<T>
      T operator-(T, T);

  concept Right<typename T> : Base<T>
      T operator+(T, T);

> A programmer creates a type called "foo" and wishes to
> make a concept map for "left" and also a concept map for "right".

  struct foo {};

  // This one would be an error, since foo doesn't have operator*
  concept_map Left<foo>
      foo operator-(foo,foo) { return 0; }

  concept_map Right<foo>
      foo operator+(foo,foo) { return 0; }

So how are you going to supply operator*? The answer to your question
depends on that.

> Because "left" is a refinement of "base", making a concept map for
> "left" implicitly makes a concept map for "base". Similarly, since
> "right" is a refinement of "base", the same thing happens. So the
> issue is, if someone now writes a function that requires a "base",
> which concept map is to be used?

I don't see a problem. If you answer the question by giving foo an
operator* of its own, the two implicitly-generated concept maps are
the same concept map.

> Should this be a compile-time error? If so, how could this possibly
> be safely resolved (does anyone know how this was handled in concept
> proposals)?

I need more information. Please try to write out a complete example
(using ConceptC++ syntax, please).

> Assuming it should be a compile-time error, would it be enough to just
> require a third concept map to be written, explicitly for base, or perhaps a
> way to specify explicitly that "right" should be used? If so, what happens
> when a function takes a "left" and that function references the parts of the
> concept map that are used to satisfy the requirements of "base"? I'd imagine
> that it would use the "left" concept map, but that means that a different
> concept map for "base" would be used depending on whether the function took
> a "base" or a "left" or a "right", which seems to be very wrong. Am I
> expressing this problem correctly? Does anyone see an obvious resolution
> that I've missed?

too many questions; too little code ;-)

Dave Abrahams
BoostPro Computing

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