Re: CT-String as a Symbol

2015-04-21 Thread via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 06:56:33 UTC, Per Nordlöw wrote: On Monday, 20 April 2015 at 13:49:41 UTC, John Colvin wrote: On Thursday, 16 April 2015 at 18:12:35 UTC, Nordlöw wrote: Is there a way to CT-query the arity of all opIndex and opSlice overloads? Further, this is slightly related

Re: CT-String as a Symbol

2015-04-21 Thread via Digitalmars-d-learn
On Monday, 20 April 2015 at 13:49:41 UTC, John Colvin wrote: On Thursday, 16 April 2015 at 18:12:35 UTC, Nordlöw wrote: Is there a way to CT-query the arity of all opIndex and opSlice overloads? Ideally you don't want to have to do that. You'd have to consider alias this and inheritance.

Re: Converting Java code to D

2015-04-21 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-04-20 20:05, Steven Schveighoffer wrote: enum LineStyle : string { NONE = None, SOLID = Solid, ... // etc } Used like this: funcThatTakesString(LineStyle.NONE); LineStyle ls = LineStyle.SOLID; funcThatTakesLineStyle(ls); I'm not a Java programmer, and my time with Java

Re: Structural exhaustive matching

2015-04-21 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-04-21 17:36, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. There's something call castSwitch [1], perhaps not what you're looking

Re: CT-String as a Symbol

2015-04-21 Thread Nordlöw
On Tuesday, 21 April 2015 at 07:46:03 UTC, Vlad Levenfeld wrote: Then you throw in some more stuff to detect 1-dimensional cases. Could you please elaborate a bit?

Re: how does isInputRange(T) actually work?

2015-04-21 Thread anonymous via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 19:17:56 UTC, kevin wrote: On Tuesday, 21 April 2015 at 19:13:34 UTC, Meta wrote: On Tuesday, 21 April 2015 at 19:11:43 UTC, John Colvin wrote: On Tuesday, 21 April 2015 at 19:06:39 UTC, kevin wrote: enum bool isInputRange = is(typeof( (inout int = 0) { R r

how does isInputRange(T) actually work?

2015-04-21 Thread kevin via Digitalmars-d-learn
enum bool isInputRange = is(typeof( (inout int = 0) { R r = R.init; // can define a range object if (r.empty) {} // can test for empty r.popFront(); // can invoke popFront() auto h = r.front; // can get the front of the range })); ... is the

Re: how does isInputRange(T) actually work?

2015-04-21 Thread kevin via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 19:13:34 UTC, Meta wrote: On Tuesday, 21 April 2015 at 19:11:43 UTC, John Colvin wrote: On Tuesday, 21 April 2015 at 19:06:39 UTC, kevin wrote: enum bool isInputRange = is(typeof( (inout int = 0) { R r = R.init; // can define a range object if

Re: how does isInputRange(T) actually work?

2015-04-21 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 19:06:39 UTC, kevin wrote: enum bool isInputRange = is(typeof( (inout int = 0) { R r = R.init; // can define a range object if (r.empty) {} // can test for empty r.popFront(); // can invoke popFront() auto h =

Re: how does isInputRange(T) actually work?

2015-04-21 Thread Meta via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 19:11:43 UTC, John Colvin wrote: On Tuesday, 21 April 2015 at 19:06:39 UTC, kevin wrote: enum bool isInputRange = is(typeof( (inout int = 0) { R r = R.init; // can define a range object if (r.empty) {} // can test for empty

Re: how does isInputRange(T) actually work?

2015-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/21/15 3:11 PM, John Colvin wrote: On Tuesday, 21 April 2015 at 19:06:39 UTC, kevin wrote: enum bool isInputRange = is(typeof( (inout int = 0) { R r = R.init; // can define a range object if (r.empty) {} // can test for empty r.popFront(); // can

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 07:01:27 UTC, Per Nordlöw wrote: On Tuesday, 21 April 2015 at 06:56:33 UTC, Per Nordlöw wrote: On Monday, 20 April 2015 at 13:49:41 UTC, John Colvin wrote: On Thursday, 16 April 2015 at 18:12:35 UTC, Nordlöw wrote: Is there a way to CT-query the arity of all

std.net.curl.get failing to resolve google.com

2015-04-21 Thread Jakob Ovrum via Digitalmars-d-learn
test.d --- void main() { import std.net.curl; import std.stdio; writeln(get(http://google.com;)); } --- rdmd -g test.d --- std.net.curl.CurlException@std\net\curl.d(3691): couldn't resolve host name on handle 26B4878 0x0040572A in pure @safe void

Re: multiSort for sorting AA by value

2015-04-21 Thread bearophile via Digitalmars-d-learn
Chris: I'm happy with it, but maybe there is a more concise implementation? This is a bit shorter and a bit better (writefln is not yet able to format tuples nicely): void main() { import std.stdio: writeln; import std.algorithm.sorting: multiSort; import std.array: array;

std.datetime.parseRFC822DateTime

2015-04-21 Thread Jakob Ovrum via Digitalmars-d-learn
std.datetime contains parseRFC822DateTime to convert from an RFC822/RFC5322 formatted string (ala Sat, 6 Jan 1990 12:14:19 -0800) to a SysTime. Does it contain anything for the converse - converting from a SysTime to Sat, 6 Jan 1990 12:14:19 -0800? If not, should it?

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
As an aside, I've put a bit of work into the generic multidimensional containers problem lately and have an interface generating library as a result. https://github.com/evenex/autodata It's still in the nascent stages but contains a lot of tools for working with multidimensional structures.

Re: multiSort for sorting AA by value

2015-04-21 Thread Chris via Digitalmars-d-learn
Maybe something like bearophile's example should go into the documentation of std.algorithm.sorting.multiSort. It's a common enough thing in programming.

Re: CT-String as a Symbol

2015-04-21 Thread via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 07:46:03 UTC, Vlad Levenfeld wrote: template dimensionality (S) { template count_dim (uint i = 0) { static if (is (typeof(S.init.opSlice!i (0,0 enum count_dim = count_dim!(i+1); else enum count_dim = i; } alias dimensionality = count_dim!();

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 08:09:38 UTC, Per Nordlöw wrote: On Tuesday, 21 April 2015 at 07:46:03 UTC, Vlad Levenfeld wrote: template dimensionality (S) { template count_dim (uint i = 0) { static if (is (typeof(S.init.opSlice!i (0,0 enum count_dim = count_dim!(i+1); else enum

Re: Reuse object memory?

2015-04-21 Thread via Digitalmars-d-learn
On Monday, 20 April 2015 at 21:36:35 UTC, Ali Çehreli wrote: final class Foo { uint id; @nogc this(uint id) { this.id = id; } } C reuse(C, T...)(ref C old, T ctorParams) { import std.conv; import std.typetuple; enum objectSize = __traits(classInstanceSize,

Re: User defined properties signatures

2015-04-21 Thread via Digitalmars-d-learn
On Monday, 20 April 2015 at 20:22:40 UTC, Jonathan M Davis wrote: There may be languages out there which take the the return type into account when overloading, but I've never seen one. Rust does, as far as I know. I don't think that the ambiguities are an insurmountable obstacle. It's

Re: User defined properties signatures

2015-04-21 Thread Dicebot via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 13:27:48 UTC, Marc Schütz wrote: On Monday, 20 April 2015 at 20:22:40 UTC, Jonathan M Davis wrote: There may be languages out there which take the the return type into account when overloading, but I've never seen one. Rust does, as far as I know. And this is

Re: std.datetime.parseRFC822DateTime

2015-04-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 21, 2015 08:14:10 Jakob Ovrum via Digitalmars-d-learn wrote: std.datetime contains parseRFC822DateTime to convert from an RFC822/RFC5322 formatted string (ala Sat, 6 Jan 1990 12:14:19 -0800) to a SysTime. Does it contain anything for the converse - converting from a SysTime

Re: std.datetime.parseRFC822DateTime

2015-04-21 Thread Jakob Ovrum via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 10:28:32 UTC, Jonathan M Davis wrote: On Tuesday, April 21, 2015 08:14:10 Jakob Ovrum via Digitalmars-d-learn wrote: std.datetime contains parseRFC822DateTime to convert from an RFC822/RFC5322 formatted string (ala Sat, 6 Jan 1990 12:14:19 -0800) to a SysTime. Does

Re: multiSort for sorting AA by value

2015-04-21 Thread Chris via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 11:46:24 UTC, bearophile wrote: Chris: I'm happy with it, but maybe there is a more concise implementation? This is a bit shorter and a bit better (writefln is not yet able to format tuples nicely): void main() { import std.stdio: writeln; import

Structural exhaustive matching

2015-04-21 Thread Jadbox via Digitalmars-d-learn
What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D.

Re: Structural exhaustive matching

2015-04-21 Thread bearophile via Digitalmars-d-learn
Jadbox: I'm curious on what the best way to do ADTs in D. Sometimes there's no best way, there are several alternative ways with different tradeoffs. D isn't a functional language and there's no really good way to do ADTs in D. You can use plus a final switch. Or you can use Algebraic from

Re: CT-String as a Symbol

2015-04-21 Thread Nordlöw
On Tuesday, 21 April 2015 at 20:30:00 UTC, Vlad Levenfeld wrote: Should work for any case I can think of (assuming integral indices). Thanks.

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
template dimensionality (S) { template count_dim (uint i = 0) { static if (is (typeof(S.init.opSlice!i (0,0 enum count_dim = count_dim!(i+1); else static if (i == 0 (isInputRange!S || is (typeof(S.init[0]))) enum count_dim = 1; else enum count_dim = i; }

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 19:46:03 UTC, Nordlöw wrote: On Tuesday, 21 April 2015 at 07:46:03 UTC, Vlad Levenfeld wrote: Then you throw in some more stuff to detect 1-dimensional cases. Could you please elaborate a bit? Well assuming the type is not multidimensional (does not define

Re: how does isInputRange(T) actually work?

2015-04-21 Thread Ali Çehreli via Digitalmars-d-learn
On 04/21/2015 12:06 PM, kevin wrote: enum bool isInputRange = is(typeof( (inout int = 0) { R r = R.init; // can define a range object if (r.empty) {} // can test for empty r.popFront(); // can invoke popFront() auto h = r.front; // can get

Re: Observing exceptions in a destructor

2015-04-21 Thread ketmar via Digitalmars-d-learn
On Wed, 22 Apr 2015 01:02:15 +, Mark Isaacson wrote: I'd like to be able to know if my destructor is being called because an exception was thrown. Any way to do that? sorry, you can't. signature.asc Description: PGP signature

Re: Observing exceptions in a destructor

2015-04-21 Thread Mark Isaacson via Digitalmars-d-learn
Oh well :(. Yeah, it's just for debugging. I want to publish a script that automatically gathers relevant debug information so that my users can just copy paste it all into one place, ready for me to take a look even if I can't repro. One of the primitives in my script is a wrapper around

Re: Observing exceptions in a destructor

2015-04-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 22, 2015 01:02:15 Mark Isaacson via Digitalmars-d-learn wrote: I'd like to be able to know if my destructor is being called because an exception was thrown. Any way to do that? I tried this: http://ideone.com/JbXH2w (Pasted here for convenience): import std.stdio,

Re: Structural exhaustive matching

2015-04-21 Thread Martin Nowak via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. If it needs to be really fast, use final switch on

extern(C++) linker errors

2015-04-21 Thread bitwise via Digitalmars-d-learn
Hello! I am trying to interface to C++, and getting linker errors. Below are my 3 source files and 2 build scripts with their associated errors. Can anyone see what I'm doing wrong? / test.cpp #include stdio.h class Test { public: virtual void Foo(){

Observing exceptions in a destructor

2015-04-21 Thread Mark Isaacson via Digitalmars-d-learn
I'd like to be able to know if my destructor is being called because an exception was thrown. Any way to do that? I tried this: http://ideone.com/JbXH2w (Pasted here for convenience): import std.stdio, std.exception; struct Catcher { ~this() { try {} catch (Exception

multiSort for sorting AA by value

2015-04-21 Thread Chris via Digitalmars-d-learn
The following works great. It sorts an AA by value: 1. by frequency of word 2. by alphabetic order (if two or more words have the same value) import std.stdio : writefln; import std.algorithm.sorting : multiSort; void main() { size_t[string] wcount = [ hamster:5, zorro:80,

Re: User defined properties signatures

2015-04-21 Thread Dicebot via Digitalmars-d-learn
This isn't about type system per se but about preferred style of syntax. Original example that caused my hatred looked like this: `let i : uint = from_str(42)`. Fortunately this has been deprecated in favor of `parse` but same principle applies - Rust authors encourage you to use declaration

Re: Structural exhaustive matching

2015-04-21 Thread weaselcat via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. D's ADTs are in std.variant, the equivalent of

Re: User defined properties signatures

2015-04-21 Thread Idan Arye via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 13:53:15 UTC, Dicebot wrote: On Tuesday, 21 April 2015 at 13:27:48 UTC, Marc Schütz wrote: On Monday, 20 April 2015 at 20:22:40 UTC, Jonathan M Davis wrote: There may be languages out there which take the the return type into account when overloading, but I've

Re: Structural exhaustive matching

2015-04-21 Thread Justin Whear via Digitalmars-d-learn
On Tue, 21 Apr 2015 15:36:27 +, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. std.variant.Algebraic implements ADTs: import