assumeSafeAppend on slice of static array?
    Ali Çehreli via Digitalmars-d 
    digitalmars-d at puremagic.com
       
    Tue Apr 22 13:44:42 PDT 2014
    
    
  
On 04/22/2014 11:10 AM, H. S. Teoh via Digitalmars-d wrote:
 > is there a way to take a slice of the static array, set the
 > length to zero,
Currently, instead of setting the length to zero, you should start with 
the whole slice.
 > and append to it with ~=
Instead, you can use the output range primitive put().
 > such that when it runs out of space in the static buffer
When slice.empty, it would have covered the static array completely:
import std.range;
void foo()
{
     int[2] buffer;
     int[] slice = buffer[];
     foreach (int i, _; slice) {
         slice.put(i);
     }
     assert(buffer == [ 0, 1 ]);
}
void main()
{
     foo();
}
Ali
    
    
More information about the Digitalmars-d
mailing list