digitalmars.D.learn - Problem with CTFE
- Sean Kelly (25/25) Dec 18 2007 Can someone tell me why compiling with version=Good works, but compiling...
- Jarrett Billingsley (7/32) Dec 18 2007 Seems like a bug to me. Using the Bad version in a non-constant context...
Can someone tell me why compiling with version=Good works, but compiling 
with version=Bad fails?
     version( Good )
     {
         size_t find(Elem)( Elem[] buf, Elem pat )
         {
             for( size_t pos = 0; pos < buf.length; ++pos )
             {
                 if( buf[pos] == pat )
                     return pos;
             }
             return buf.length;
         }
     }
     else version( Bad )
     {
         size_t find(Buf, Pat)( Buf buf, Pat pat )
         {
             return 0;
         }
     }
     const pos = find( "abcdefg", 'c' );
     void main()
     {
     }
 Dec 18 2007
"Sean Kelly" <sean f4.ca> wrote in message 
news:fk98ve$2mgq$1 digitalmars.com...
 Can someone tell me why compiling with version=Good works, but compiling 
 with version=Bad fails?
     version( Good )
     {
         size_t find(Elem)( Elem[] buf, Elem pat )
         {
             for( size_t pos = 0; pos < buf.length; ++pos )
             {
                 if( buf[pos] == pat )
                     return pos;
             }
             return buf.length;
         }
     }
     else version( Bad )
     {
         size_t find(Buf, Pat)( Buf buf, Pat pat )
         {
             return 0;
         }
     }
     const pos = find( "abcdefg", 'c' );
     void main()
     {
     }
Seems like a bug to me.  Using the Bad version in a non-constant context 
works fine.  Using the Bad version with explicitly-specified types in a 
constant context also works fine.  Maybe some kind of ordering bug in the 
compiler; it doesn't deduce the two types before it tries to evaluate it or 
something. 
 Dec 18 2007








 
  
  
  "Jarrett Billingsley" <kb3ctd2 yahoo.com>
 "Jarrett Billingsley" <kb3ctd2 yahoo.com>