Boost logo

Boost :

Subject: Re: [boost] [contract] extra type requirements for contracts
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-09-23 01:42:54


On Thu, Sep 22, 2011 at 10:25 PM, Brent Spillner <spillner_at_[hidden]> wrote:

> On Thu, 22 Sep 2011 08:03:09 lcaminiti wrote:
> >For example, the following code asserts back() == value only when
> >can_call_equal<T>::value is true. However, is there a better way to do
> this
> >that does not require the extra function call to post1?
>
> Unless I'm missing something, you should be able to replace the
> post1() calls with
>
> assert(boost::can_call_equal<T>::value && std::clog << "actual
> assertion\n" == std::clog && back() == value || std::clog << "trivial
> assertion\n" == std::clog);
>

Unfortunately, the compiler can't do a "syntactic short-circuit" when
!can_call_equal<T>::value and simply skip over the "back() == value"
expression; "back() == value" still needs to be a valid expression, i.e., if
an appropriate operator== isn't found, you'll still get a compiler error :(

Compare to

false && (pretty-sure*the==compiler&wont^like%this)

...at least most of the time, anyway...

- Jeff


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