D - assert on module level
- Roel Mathys (11/12) Jan 14 2004 // tst2.d
- J Anderson (4/16) Jan 14 2004 What are you trying to do?
- Roel Mathys (74/103) Jan 14 2004 simplified the code to show my problem, thanks for the help.
// tst2.d assert (true); // end tst2.d // tst.d import tst2; void main() {} // end tst.d <<<<<<<<<<<<<<<<<<<<< The above does not work, is this by design? thx, roel
Jan 14 2004
Roel Mathys wrote:What are you trying to do? Try static assert(true);// tst2.d assert (true); // end tst2.d // tst.d import tst2; void main() {} // end tst.d <<<<<<<<<<<<<<<<<<<<< The above does not work, is this by design? thx, roel
Jan 14 2004
J Anderson wrote:Roel Mathys wrote:simplified the code to show my problem, thanks for the help. tried to build a little stack in D, I had some module level constants. Wanted to add a consistency check. thx, rm ps: code follows, if anyone is interested ------------------------------------- class FullStack {} class EmptyStack {} private const uint growFactor = 2; private const uint shrinkFactor = 2; private const uint shrinkTreshold = 3; private const uint startSize = 8; static assert ( shrinkFactor < shrinkTreshold ); template TStack(T) { class Stack { private T[] values_; private uint nxt_; private uint maxDepth_; this() { this( nxt_.max, startSize ); } this( uint maxdepth ) { this( maxdepth, startSize ); } this( uint maxdepth, uint startsize ) { maxDepth_ = maxdepth; values_.length = startsize; } int size() {return nxt_; } void push( T t ) { grow(); values_[nxt_++] = t; } void grow() { if ( nxt_ == maxDepth_ ) throw new FullStack; if ( nxt_ == values_.length ) if ( maxDepth_ / growFactor >= values_.length ) values_.length = values_.length * growFactor; else values_.length = maxDepth_; } T pop() { if ( nxt_ == nxt_.min ) throw new EmptyStack; shrink(); return values_[--nxt_]; } void shrink() { if ( shrinkTreshold * nxt_ < values_.length ) values_.length = values_.length / shrinkFactor; } } } //unittest void main() { alias instance TStack(int).Stack IntStack; IntStack x = new IntStack; for (int j=0;j<20;++j) { x.push( j ); } for (int j=0;j<20;++j) { printf( "%d ",x.pop()); } printf(\n); }What are you trying to do? Try static assert(true);// tst2.d assert (true); // end tst2.d // tst.d import tst2; void main() {} // end tst.d <<<<<<<<<<<<<<<<<<<<< The above does not work, is this by design? thx, roel
Jan 14 2004