Boost logo

Boost :

Subject: Re: [boost] [contract] concepts: pseudo-signatures vs. usage patterns
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-10-14 14:57:52

on Sun Oct 14 2012, Andrzej Krzemienski <> wrote:

> 2012/10/14 Dave Abrahams <dave_at_[hidden]>
>> on Sat Oct 13 2012, Andrzej Krzemienski <> wrote:
>> > I was trying to say that pseudo-signatures look like normal signatures
>> > and might imply that no "loose match" occurs. In contrast, usage
>> > patterns look like expressions, and you do expect implicit
>> > conversions. Although, I do not find it a major argument against
>> > pseudo-signatures.
>> >
>> >> Notationally speaking, I think
>> >> pseudo-signatures are *much* more suggestive of those semantics than are
>> >> valid expressions.
>> >
>> > Could you show an example where this is the case?
>> The example you gave illustrates it, IMO. This is obviously subjective,
>> but when you read the requirements as saying "this expression must be
>> convertible to bool" there's no obvious reason that when the expression
>> appears in a larger context, that conversion necessarily happens.
>> > I may be missing something obvious, but I would say it is the other
>> > way around.
>> All you have to do is think of the concept and its pseudo-signatures as
>> conceptually defining a wrapper interface over the concrete model of the
>> concept, through which the constrained function has all interactions
>> with the model, and the implicit conversions fall out as a consequence
>> of regular language rules. If you follow this mental model for the
>> concepts mechanism, many things (some outside the scope of this
>> discussion) fall into place logically... or at least they do for me.
> Can you help me understand one thing about pseudo-signatures? If I have the
> following concept:
> concept MyIter<typename It>
> {
> It& operator++(It&);
> bool It::is_valid();
> }
> Does this say preincrement returns exactly reference to It or only
> something convertible to It?

It says that

* the preincrement of a /model/ of MyIter must return something
  convertible to It&

* WHen a function constrained to using the MyIter concept preincrements
  an instance of MyIter, it sees exactly It& returned, regardless of
  what is actually returned by the model's preincrement operation.

> If it is the latter, it would mean that the concept model where
> pre-increment only returns something convertible to It& satisfies the
> concept, but makes the following usage invalid:
> template <MyIter It>
> void test_next(It i)
> {
> return (++it).is_valid();
> }
> Or am I wrong?

By the 2nd bullet, test_next sees (++it) as having type It&, regardless
of what is actually returned by the model's preincrement operator. That
is, a conversion is forced if the return type is not exactly It&.

Dave Abrahams
BoostPro Computing                  Software Development        Training             Clang/LLVM/EDG Compilers  C++  Boost

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