std.base64 question

Adam D. Ruppe destructionator at gmail.com
Tue Nov 26 18:49:17 PST 2013


On Wednesday, 27 November 2013 at 02:43:56 UTC, Parke wrote:
> [snip]/src/phobos/std/range.d(614): Error: static assert  
> "Cannot put a immutable(char) into a char[40]"

Static arrays aren't considered ranges in templates because their 
length can't change. If you slice it, however, it will work, 
since a slice is a valid range:

import std.base64;
ubyte[]  s0 = ['H','e','l','l','o'];
char[40] s1;
void main () {
   import std.stdio;
   auto encodedData = Base64.encode (s0, s1[]); // notice the []
   writeln(encodedData);
}


Then base64.encode returns the slice into the string that it 
actually used.

The slice operator, [], returns a view into the array that can be 
advanced by the encode function as needed.


More information about the Digitalmars-d-learn mailing list