Re: more OO way to do hex string to bytes conversion

2018-02-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 7 February 2018 at 14:47:04 UTC, Ralph Doncaster wrote: p.s. the cast should probably be to immutable ubyte[]. I'm guessing without it, there is an automatic copy of the data being made. No copy - you just get undefined behavior if you actually try to modify it!

Re: more OO way to do hex string to bytes conversion

2018-02-07 Thread Ralph Doncaster via Digitalmars-d-learn
On Tuesday, 6 February 2018 at 18:33:02 UTC, Ralph Doncaster wrote: I've been reading std.conv and std.range, trying to figure out a high-level way of converting a hex string to bytes. The only way I've been able to do it is through pointer access: import std.stdio; import std.string; import

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread rikki cattermole via Digitalmars-d-learn
On 07/02/2018 4:06 AM, Craig Dillabaugh wrote: On Wednesday, 7 February 2018 at 03:25:05 UTC, rikki cattermole wrote: On 06/02/2018 8:46 PM, Craig Dillabaugh wrote: On Tuesday, 6 February 2018 at 18:46:54 UTC, H. S. Teoh wrote: [...] clip [...] clip [...] Wouldn't it be more accurate to

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread Craig Dillabaugh via Digitalmars-d-learn
On Wednesday, 7 February 2018 at 03:25:05 UTC, rikki cattermole wrote: On 06/02/2018 8:46 PM, Craig Dillabaugh wrote: On Tuesday, 6 February 2018 at 18:46:54 UTC, H. S. Teoh wrote: [...] clip [...] clip [...] Wouldn't it be more accurate to say OO is not the correct tool for every job

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread rikki cattermole via Digitalmars-d-learn
On 06/02/2018 8:46 PM, Craig Dillabaugh wrote: On Tuesday, 6 February 2018 at 18:46:54 UTC, H. S. Teoh wrote: On Tue, Feb 06, 2018 at 06:33:02PM +, Ralph Doncaster via Digitalmars-d-learn wrote: clip OO is outdated.  D uses the range-based idiom with UFCS for chaining operations in a

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread Ali Çehreli via Digitalmars-d-learn
On 02/06/2018 11:55 AM, Ralph Doncaster wrote: > I'll have to do some more reading about > maps. My initial though is they don't seem as readable as loops. Surprisingly, they may be very easy to read in some situations. > The chunks() is useful, so for now what I'm going with is: >

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread Craig Dillabaugh via Digitalmars-d-learn
On Tuesday, 6 February 2018 at 18:46:54 UTC, H. S. Teoh wrote: On Tue, Feb 06, 2018 at 06:33:02PM +, Ralph Doncaster via Digitalmars-d-learn wrote: clip OO is outdated. D uses the range-based idiom with UFCS for chaining operations in a way that doesn't require you to write loops

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/6/18 1:46 PM, H. S. Teoh wrote: Of course, this eagerly constructs an array to store the result, which allocates, and also requires the hex string to be fully constructed first. You can make this code lazy by turning it into a range algorithm, then you can actually generate the hex digits

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread Ralph Doncaster via Digitalmars-d-learn
On Tuesday, 6 February 2018 at 18:33:02 UTC, Ralph Doncaster wrote: I've been reading std.conv and std.range, trying to figure out a high-level way of converting a hex string to bytes. The only way I've been able to do it is through pointer access: import std.stdio; import std.string; import

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread Machin via Digitalmars-d-learn
On Tuesday, 6 February 2018 at 18:33:02 UTC, Ralph Doncaster wrote: I've been reading std.conv and std.range, trying to figure out a high-level way of converting a hex string to bytes. The only way I've been able to do it is through pointer access: import std.stdio; import std.string; import

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread ag0aep6g via Digitalmars-d-learn
On 02/06/2018 07:33 PM, Ralph Doncaster wrote: I've been reading std.conv and std.range, trying to figure out a high-level way of converting a hex string to bytes.  The only way I've been able to do it is through pointer access: import std.stdio; import std.string; import std.conv; void

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 06, 2018 at 06:33:02PM +, Ralph Doncaster via Digitalmars-d-learn wrote: > I've been reading std.conv and std.range, trying to figure out a > high-level way of converting a hex string to bytes. The only way I've > been able to do it is through pointer access: > > import

more OO way to do hex string to bytes conversion

2018-02-06 Thread Ralph Doncaster via Digitalmars-d-learn
I've been reading std.conv and std.range, trying to figure out a high-level way of converting a hex string to bytes. The only way I've been able to do it is through pointer access: import std.stdio; import std.string; import std.conv; void main() { immutable char* hex =