Re: Handling arbitrary char ranges

2016-04-20 Thread ag0aep6g via Digitalmars-d-learn
On 21.04.2016 04:35, Alex Parrill wrote: On Wednesday, 20 April 2016 at 22:44:37 UTC, ag0aep6g wrote: On 20.04.2016 23:59, Alex Parrill wrote: [...] That's not assigning the elements of a void[]; it's just changing what the slice points to and adjusting the length, like doing `void* ptr =

Re: Handling arbitrary char ranges

2016-04-20 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 22:44:37 UTC, ag0aep6g wrote: On 20.04.2016 23:59, Alex Parrill wrote: On Wednesday, 20 April 2016 at 17:09:29 UTC, Matt Kline wrote: [...] First, you can't assign anything to a void[], for the same reason you can't dereference a void*. This includes the slice

Re: Handling arbitrary char ranges

2016-04-20 Thread ag0aep6g via Digitalmars-d-learn
On 20.04.2016 23:59, Alex Parrill wrote: On Wednesday, 20 April 2016 at 17:09:29 UTC, Matt Kline wrote: [...] First, you can't assign anything to a void[], for the same reason you can't dereference a void*. This includes the slice assignment that you are trying to do in `buf[0..minLen] =

Re: Handling arbitrary char ranges

2016-04-20 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 17:09:29 UTC, Matt Kline wrote: [...] First, you can't assign anything to a void[], for the same reason you can't dereference a void*. This includes the slice assignment that you are trying to do in `buf[0..minLen] = remainingData[0..minLen];`. Cast the

Re: Handling arbitrary char ranges

2016-04-20 Thread ag0aep6g via Digitalmars-d-learn
On 20.04.2016 22:09, Matt Kline wrote: I'd rather not write my own cURL wrapper. Do you think it would be worthwhile starting a PR for Phobos to get it changed to ubyte[]? A reading of https://dlang.org/spec/arrays.html indicates the main difference is that that GC crawls void[], but I would

Re: Handling arbitrary char ranges

2016-04-20 Thread Matt Kline via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 20:00:58 UTC, ag0aep6g wrote: Maybe I've missed it, but you didn't say where the HTTP type comes from, did you? std.net.curl: https://dlang.org/phobos/std_net_curl.html#.HTTP (Sorry, I assumed that was a given since it's a standard library type. Poor

Re: Handling arbitrary char ranges

2016-04-20 Thread ag0aep6g via Digitalmars-d-learn
On 20.04.2016 21:48, Matt Kline wrote: I don't have an option here, do I? I assume HTTP.onSend doesn't take a `delegate size_t(ubyte[])` insetad of a `delegate size_t(void[])`, and that the former isn't implicitly convertible to the latter. Maybe I've missed it, but you didn't say where the

Re: Handling arbitrary char ranges

2016-04-20 Thread Matt Kline via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 19:29:22 UTC, ag0aep6g wrote: Maybe use ubyte[] for the buffer type instead. I don't have an option here, do I? I assume HTTP.onSend doesn't take a `delegate size_t(ubyte[])` insetad of a `delegate size_t(void[])`, and that the former isn't implicitly

Re: Handling arbitrary char ranges

2016-04-20 Thread ag0aep6g via Digitalmars-d-learn
On 20.04.2016 19:09, Matt Kline wrote: 1. What is the idiomatic way to constrain the function to only take char ranges? One might naïvely add `is(ElementType!T : char)`, but that falls on its face due to strings "auto-decoding" their elements to dchar. (More on that later.) Well, string is not

Re: Handling arbitrary char ranges

2016-04-20 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 17:09:29 UTC, Matt Kline wrote: I'm doing some work with a REST API, and I wrote a simple utility function that sets an HTTP's onSend callback to send a string: [...] IO functions usually work with octets, not characters, so an extra encoding step is needed.