Sophisticated constraint checks

Stephen M. Webb stephenw@xandros.com
Thu Mar 3 19:38:00 GMT 2005


Hello all

I'm beavering away trying to implement the TR1 [5.1] random stuff and I need 
to add a number of constraint checks.  I'm using concept requirements where 
possible and __enable_if<> where I need to constrain a templated type based 
on a type trait, but I need more.

First, some functions have strict constraints on input domain at runtime, 
which to me says throw an exception but TR1 seems to forbid this.  Is using 
_GLIBCXX_DEBUG_ASSERT() to raise an assertion only in debug mode really the 
best that can be done?

Second, a number of templates have integer-valued parameters that have 
compile-time constraints (for example, class discard_block<typename, int p, 
int r> has constraints 0 <= r <= p).  I can either do something fancy with 
__enable_if<>, which will emit a confusing message to the unwary, or invent 
something of my own and leave it in the random header (not "a" random header, 
that would be wrong).  Better yet, perhaps there is already something 
available in the library that I've missed?

Which, in your esteemed collective opinion, would be the best way to constrain 
these template parameters?

--
Stephen M. Webb



More information about the Libstdc++ mailing list