Boost logo

Boost :

Subject: Re: [boost] [Review.Contract] Vicente's review
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-09-16 21:27:39


on Tue Sep 04 2012, Lorenzo Caminiti <lorcaminiti-AT-gmail.com> wrote:

> Just to consider all alternatives, we could also do this:
>
> CONTRACT_FUNCTION(
> template( typename To, typename From )
> if( // used with enable_if in the declaration part
> is_convertible<From, To>::value,
> is_convertible<To, From>::value
> )

+1 for "if." Andrzej's "enable_if" suggestion is nice and more explicit
too, but there's no syntax highlighting bonus. I'm torn.

> requires( // included in the function body

The fact that this is "included in the function body" is irrelevant I
think. I guess the real point you're trying to make is that it
generates hard errors at acompile time when violated. That suggests
something like "asserts" instead of "requires."

> static_assert(sizeof(To) >= sizeof(From), "destination too small"),
> boost::Copyable<From>
> )
> (To*) memcopy ( (To*) to, (From*) from )
> precondition(
> to; // pointer not null
> from; // pointer not null
> )
> ) {
> // ...
> }

-- 
Dave Abrahams
BoostPro Computing                  Software Development        Training
http://www.boostpro.com             Clang/LLVM/EDG Compilers  C++  Boost

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