This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Sophisticated constraint checks


Jonathan Wakely wrote:
<snip>
Or something like this is pretty clear, but not re-usable, and the extra
"divide by zero" and "not integer constant" noise in the diagnostic might
confuse some people more than it helps:

  template <typename T, int p, int r>
    class discard_block
    {
      // constraints 0 <= r <= p
      enum { _Require_r_not_less_than_zero = (1/(0<=r)) };
      enum { _Require_r_not_greater_than_p = (1/(r<=p)) };
    };

Just on this note, I remember hearing some time ago that gcc might in 4.1 be gaining some kind of static_assert, so we could write something like:


static_assert(r>=0,"Block cannot be of negative length(%d),r);
static_assert(r<=p,"Length of block (%d) must be less than the maximum(%d)",r,p);


(not actually good / correct error messages!)

Does anyone know if such a thing is likely to appear? and I am alone in thinking such a thing would make much of the checking much easier to follow?

Unfortunatly, this doesn't fix all problems, in particular while people have managed to create templates to check things like if "a==b" is a valid expression, such templates are really, really complicated and perhaps could be easied by compiler support...

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]