Compiletime Table

D_Learner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 13 12:13:52 PDT 2015


I was wondering how I could change the code below such the `bmBc` 
is computed at compile time . The one below works for runtime but 
it is not ideal since I need to know the  `bmBc` table at 
compile-time . I could appreciate advice on how I could improve 
on this.



     import std.conv:to;
     import std.stdio;

     int [string]  bmBc;
     immutable string pattern = "GCAGAGAG";
     const int size = to!int(pattern.length);

      struct king {

             void  calculatebmBc(int i)()
             {
                     static if ( i < size -1 )
                            
bmBc[to!string(pattern[i])]=to!int(size-i-1);

                   //        bmBc[pattern[i]] ~= i-1;

                     calculatebmBc!(i+1)();
             }
             void calculatebmBc(int i: size-1)() {

             }
     }

     void main(){
       king myKing;

       const  int start = 0;
       myKing.calculatebmBc!(start)();
      //1.   enum  bmBcTable =  bmBc;

     }




More information about the Digitalmars-d-learn mailing list