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 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

Handling arbitrary char ranges

2016-04-20 Thread Matt Kline via Digitalmars-d-learn
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: @property outgoingString(ref HTTP request, const(void)[] sendData) { import std.algorithm : min; request.contentLength = sendData.length;

Re: Detecting premature end of spawned threads with std.concurrency

2015-09-04 Thread Matt Kline via Digitalmars-d-learn
On Friday, 4 September 2015 at 08:33:08 UTC, Marc Schütz wrote: They're called `OwnerTerminated` and `OwnerFailed` with an "r". No, that's received by the child if the owning thread exits. I'm talking about the "parent" thread attempting to send to a child thread that has exited. Relevant

Detecting premature end of spawned threads with std.concurrency

2015-09-03 Thread Matt Kline via Digitalmars-d-learn
TDPL suggests that calls to std.concurrency.send will fail with an "OwnedTerminated" or "OwnedFailed" exception if the destination thread has exited, but neither the docs nor the current Phobos implementation make any mention of such exceptions. Thinking the information was just outdated, I

Coercing ranges to the same type

2015-07-06 Thread Matt Kline via Digitalmars-d-learn
Say I'm trying to expand an array of file and directory paths (such as ones given as command line args) into a range of file paths I can iterate over. A simplified example might be: auto getEntries(string[] paths, bool recursive) { auto files = paths.filter!(p = p.isFile); if

Re: Coercing ranges to the same type

2015-07-06 Thread Matt Kline via Digitalmars-d-learn
As it turns out, inputRangeObject does an excellent job at this task. The solution then becomes something like: InputRange!string getEntries(string[] paths, bool recursive) { auto files = paths.filter!(p = p.isFile); if (recursive) { auto expandedDirs = paths

Re: Coercing ranges to the same type

2015-07-06 Thread Matt Kline via Digitalmars-d-learn
On Monday, 6 July 2015 at 21:35:53 UTC, Alex Parrill wrote: They aren't actually the same types I understand the problem - I was just wondering if there was a standard library solution to this or if I would have to roll my own. use a class wrapper in std.range.interface [1]. [1]:

Re: Distinguish recursive Templates

2015-05-22 Thread Matt Kline via Digitalmars-d-learn
On Friday, 22 May 2015 at 21:13:50 UTC, Manfred Nowak wrote: How can one determine the recursion depth for templated types? Example code: import std.stdio; class Set(T){ override string toString(){ return Set; } } void main(){ auto s0= new Set!uint; writeln( s0); // writes Set

Mimicking C++'s indexing behavior in D associative arrays

2015-02-17 Thread Matt Kline via Digitalmars-d-learn
In C++, the index operator for maps will either return a reference to the existing value if the key can be found, or a reference to a new, default-initialized value if one with the given key cannot be found. In D, an exception is thrown instead when a value with the given key cannot be

Re: Mimicking C++'s indexing behavior in D associative arrays

2015-02-17 Thread Matt Kline via Digitalmars-d-learn
On Wednesday, 18 February 2015 at 00:21:11 UTC, Matt Kline wrote: if (value) { should of course be if (!value) { Sorry for the typo.