Boost logo

Boost :

Subject: Re: [boost] RFC Expression Validity Asserts
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2015-01-26 14:37:30

On Sun, Jan 25, 2015 at 5:19 AM, Piotr Wygocki <vwygos_at_[hidden]> wrote:

> Hi, this library might be very useful in a library I'm involved in.
> Particularly we've developed an interface for linear programing. In the
> implementation we needed to ensure that this expression compiles:
> Column x , y;
> 0 <= x + y <= 10;
> And this:
> 0 <= x + y >= 10;
> does not.
> We have very ugly solution now and I guess this is a perfect use case for
> this library.

Yeah, that would be trivial to check with this. Unfortunately, I can't seem
to get it to work consistently across compilers or even consistently within
a single compiler.

The most compelling thing about this, IMO, is that because it is itself an
expression and doesn't require separate statements, it would be usable
directly with enable_if, so if it can be made to work portably you could,
for example, write a function template that is enabled if a certain
operation is *not* supported (or if a certain operation is or is not
constexpr), which without a trick like this requires at least another
declaration to perform the SFINAE magic with a separate metafunction. With
this, everything would be able to be done entirely as a part of the
function template declaration itself.

-Matt Calabrese

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