digitalmars.D.learn - Structs and compiletime evaluation
- D_Learner (33/33) Aug 13 2015 I am having this struct :-
- Rikki Cattermole (5/18) Aug 13 2015 No it wouldn't be. It's declared for runtime usage. Not compile
- D_Learner (3/23) Aug 13 2015 Thanks Rikki, but what do you mean by AA's ?
- Rikki Cattermole (3/25) Aug 13 2015 Associative Array.
I am having this struct :- struct COMPILETIME_BM_PRE { void initialisebmBc(S,C,I,int k)( const S pattern ,ref I[C] bmBc){ static if ( k< ASIZE ){ bmBc[ALPHABET[k]] = size; initialisebmBc!(S,C,I,k+1)( pattern ,bmBc); } } void initialisebmBc(S,C,I,int k : ASIZE)( const S pattern ,ref I[C] bmBc){} void calculatebmBc(S,C,I,int i)( const S pattern ,ref I[C] bmBc) { static if ( i < size -1 ) bmBc[pattern[i]] = size -i-1; calculatebmBc!(S,C,I,i+1)(pattern ,bmBc); } I[C] preBmBc(S ,C,I)( const S pattern ,ref I[C] bmBc){ this.initialisebmBc!(S,C,I,0)( pattern ,bmBc); this.calculatebmBc!(S,C,I,0)(pattern ,bmBc); return bmBc; } } In another module I use the struct as below :- int[char] bmBc; COMPILETIME_BM_PRE bmh ; enum bmBc1 = bmh.preBmBc!(string ,char,int)( pattern , bmBc); On last line , I get the error message : `Error: variable bmh cannot be read at compile time` , yet I thought this value would be evaluated at compiletime.
Aug 13 2015
On Thursday, 13 August 2015 at 12:07:48 UTC, D_Learner wrote:I am having this struct :- struct COMPILETIME_BM_PRE { void initialisebmBc(S,C,I,int k)( const S pattern ,ref I[C] bmBc){ static if ( k< ASIZE ){ bmBc[ALPHABET[k]] = size; initialisebmBc!(S,C,I,k+1)( pattern ,bmBc); } } void initialisebmBc(S,C,I,int k : ASIZE)( const S pattern ,ref I[C] bmBc){} [...]No it wouldn't be. It's declared for runtime usage. Not compile time. Also bmBc isn't declared as an enum (can't be in fact, bug with AA's). So even if bmh was accessible, bmBc isn't.
Aug 13 2015
On Thursday, 13 August 2015 at 12:21:44 UTC, Rikki Cattermole wrote:On Thursday, 13 August 2015 at 12:07:48 UTC, D_Learner wrote:Thanks Rikki, but what do you mean by AA's ?I am having this struct :- struct COMPILETIME_BM_PRE { void initialisebmBc(S,C,I,int k)( const S pattern ,ref I[C] bmBc){ static if ( k< ASIZE ){ bmBc[ALPHABET[k]] = size; initialisebmBc!(S,C,I,k+1)( pattern ,bmBc); } } void initialisebmBc(S,C,I,int k : ASIZE)( const S pattern ,ref I[C] bmBc){} [...]No it wouldn't be. It's declared for runtime usage. Not compile time. Also bmBc isn't declared as an enum (can't be in fact, bug with AA's). So even if bmh was accessible, bmBc isn't.
Aug 13 2015
On 14/08/2015 12:48 a.m., D_Learner wrote:On Thursday, 13 August 2015 at 12:21:44 UTC, Rikki Cattermole wrote:Associative Array. Other names e.g. map.On Thursday, 13 August 2015 at 12:07:48 UTC, D_Learner wrote:Thanks Rikki, but what do you mean by AA's ?I am having this struct :- struct COMPILETIME_BM_PRE { void initialisebmBc(S,C,I,int k)( const S pattern ,ref I[C] bmBc){ static if ( k< ASIZE ){ bmBc[ALPHABET[k]] = size; initialisebmBc!(S,C,I,k+1)( pattern ,bmBc); } } void initialisebmBc(S,C,I,int k : ASIZE)( const S pattern ,ref I[C] bmBc){} [...]No it wouldn't be. It's declared for runtime usage. Not compile time. Also bmBc isn't declared as an enum (can't be in fact, bug with AA's). So even if bmh was accessible, bmBc isn't.
Aug 13 2015