Boost logo

Boost :

Subject: Re: [boost] [contract] extra type requirements for contracts
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2011-09-23 09:23:04

Brent Spillner wrote:
> On Fri, Sep 23, 2011 at 5:25 AM, Brent Spillner <spillner_at_[hidden]>
> wrote:
>> Unless I'm missing something, you should be able to replace the
> Oof, I sure was... that's what I get for posting at 2 in the morning.
> I can't see any way around an extra function, but I would probably
> encapsulate it with something like
> template < class T, class U > typename boost::enable_if_c<
> can_call_equal<T>::value, bool >::type
> equality_test(const T &t, const U &u) { return t == u; }
> bool equality_test(...) { return true; }
> to avoid littering the generated class with a bunch of one-off postN()s.

Using equality_test works for back() == value. However, in general the
assertion can be as complex as you wish so I need to introduce general extra
functions postN (littering the user class, my library already litters the
user class quite a bit with a number of extra functions, about +5 functions
for every member function!! to check pre/postconditions, subcontract, and
copy old-ofs). The extra postN functions are only introduced when requires
is used on an assertion, so you can chose between generality of the
contracts and the cost of the extra functions (to compile and call).

A more complex example:

    auto result = return,
    result == x + y, requires has_equal_to<T>::value && has_plus<T>::value

I can't use equality_test here. (This could work with T = int, T =
std::string, etc.)

You can construct an arbitrary complex example:

struct airplane {
    bool started ( ) const { ... }
    bool flying () const { ... }

struct car {
    bool started ( ) const { ... }
    bool driving () const { ... }

    machine.started() && machine.flying(), requires is_airplane<Machine>,
    machine.started() && machine.driving(), requires is_car<Machine>

OK this is a silly example, intentionally complex, but it's just to
illustrate that equality_test is not generic enough and it won't work in
this case.


View this message in context:
Sent from the Boost - Dev mailing list archive at

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