|  |  | 
| |  | Posted by Roel Mathys in reply to J Anderson
 |  Permalink  Reply | 
 | 
| Roel Mathys  
 Posted in reply to J Anderson
 
 | J Anderson wrote:
> Roel Mathys wrote:
> 
>> >>>>>>>>>>>>>>>>>>>>>
>>
>> // 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
> 
> 
> What are you trying to do?
> 
> Try
> static assert(true);
> 
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);
}
 |