The original code I was using was written in Java, and only had
a method for strings. This is closer to what I wanted. My unit
tests were just going back and forth with readString function,
so I was completely missing this for other types. Nice catch!
There were a couple issues with your cod
On Saturday, 7 February 2015 at 12:04:12 UTC, Nicholas Wilson
wrote:
Are you wanting to to convert each element in arr to a byte
thus truncating and losing data (when T.sizeof != 1)?
as in
toBytes([1,2,3, 42, 500 /*this will be truncated to 244
*/]);// T == int here
or are you wanting to c
On Friday, 6 February 2015 at 17:09:29 UTC, Charles wrote:
I'm trying to create a template function that can take in any
type of array and convert it to a ubyte array. I'm not
concerned with endianness at the moment, but I ran into a
roadblock when trying to do this with strings. It already wor
On Friday, 6 February 2015 at 17:40:31 UTC, ketmar wrote:
On Fri, 06 Feb 2015 17:09:28 +, Charles wrote:
readString(toBytes!string("test"),0,4).writeln;
if you'll take a look into druntime sources, you'll find that
string is
just an alias to `immutable(char)[]`. so you actually
On Fri, 06 Feb 2015 17:09:28 +, Charles wrote:
> readString(toBytes!string("test"),0,4).writeln;
if you'll take a look into druntime sources, you'll find that string is
just an alias to `immutable(char)[]`. so you actually doing thing:
readString(toBytes!(immutable(char)[])("test
On 2015-02-06 at 18:09, Charles wrote:
readString(toBytes!char(['t','e','s','t']),0,4).writeln;
readString(toBytes!string("test"),0,4).writeln;// This is line 39
That second line makes no sense (you didn't provide an array of strings).
Why toBytes!string("test") and not to
Can I not do this cast because it's immutable?
I'm trying to create a template function that can take in any
type of array and convert it to a ubyte array. I'm not concerned
with endianness at the moment, but I ran into a roadblock when
trying to do this with strings. It already works with ints,
chars, etc.
Here's the relevant test code: