Dub + Optlink == ???

2015-03-08 Thread David Held via Digitalmars-d-learn
Since DDT (Eclipse plugin) uses Dub, I am trying to convert the DWT build instructions into Dub. Here is my current attempt: { name : foo, description : foo, importPaths : [ d:/workspace/dwt/imp ], stringImportPaths : [ D:/workspace/dwt/org.eclipse.swt.win32.win32.x86/res ],

Re: Dub + Optlink == ???

2015-03-08 Thread David Held via Digitalmars-d-learn
On 3/8/2015 3:55 PM, David Held wrote: Since DDT (Eclipse plugin) uses Dub, I am trying to convert the DWT build instructions into Dub. Here is my current attempt: { name : foo, description : foo, importPaths : [ d:/workspace/dwt/imp ], stringImportPaths : [

Re: appender!(string[]).put(string) doesn't work

2015-02-08 Thread David Held via Digitalmars-d-learn
On 2/8/2015 4:09 PM, David Held wrote: auto data = appender!(string[]); ... data.put(someString); [...] Never mind. someString is actually the result of stdin.byLine(), which returns a char[], not a string. I didn't notice this until just now. .idup fixes this just fine

appender!(string[]).put(string) doesn't work

2015-02-08 Thread David Held via Digitalmars-d-learn
auto data = appender!(string[]); ... data.put(someString); source\colony.d(360): Error: template std.array.Appender(string[]).Appender.put does not match any function template declaration. Candidates are: D:\D\dmd2\windows\bin\..\..\src\phobos\std\array.d(2251):

Re: Array toHash()

2014-11-29 Thread David Held via Digitalmars-d-learn
On 11/26/2014 4:40 PM, Ali Çehreli wrote: [...] override size_t toHash() @trusted pure const nothrow { auto func = assumePure((typeid(importantStuff).getHash)); return func(importantStuff); } Very helpful, thanks! Am I right in assuming that there is some

Re: Array toHash()

2014-11-29 Thread David Held via Digitalmars-d-learn
On 11/29/2014 3:59 PM, Ali Çehreli wrote: [...] typeid() is a runtime function. I think it will be costly every time toHash is called. The function pointer can be initialized once. // I've deduced the type from an error message. ;) static const ulong delegate(const(void*)) const pure

Array toHash()

2014-11-26 Thread David Held via Digitalmars-d-learn
I have a class which contains an int[] and some other stuff. I want to use my class as the key for an AA, so I am overriding toHash(). But the int[] is the only part which should produce the hash code. I know that int[].toHash() is defined somehow, because I can put int[] directly into an

Re: Casting in Safe D

2014-11-26 Thread David Held via Digitalmars-d-learn
On 11/23/2014 3:12 PM, anonymous wrote: [...] And even pointer dereferencing is @safe. Invalid ones will fail with a segfault at run time: void foo(int* a) @safe {*a = 13;} Hmm...throwing an exception is a well-defined behavior, but is segfaulting a well-defined behavior of correct D

randomSample

2014-05-17 Thread David Held via Digitalmars-d-learn
How do I get an array from randomSample()? int[] source = [ ... ]; int[] sample = randomSample(source, 3); src\main.d(30): Error: cannot implicitly convert expression (randomSample(source, 3u)) of type RandomSample!(int[], void) to int[] I get that RandomSample is a struct which implements

Re: randomSample

2014-05-17 Thread David Held via Digitalmars-d-learn
On 5/17/2014 9:18 PM, David Held wrote: How do I get an array from randomSample()? int[] source = [ ... ]; int[] sample = randomSample(source, 3); src\main.d(30): Error: cannot implicitly convert expression (randomSample(source, 3u)) of type RandomSample!(int[], void) to int[] [...] Even

map!(char)(string) problem

2014-05-03 Thread David Held via Digitalmars-d-learn
import std.algorithm; int toInt(char c) { return 1; } void main() { map!(a = toInt(a))(hello); } Can someone please explain why I get this: Bug.d(10): Error: function Bug.toInt (char c) is not callable using argument types (dchar)

Re: Is this a bug?

2014-04-29 Thread David Held via Digitalmars-d-learn
On 4/29/2014 10:01 AM, Meta wrote: On Tuesday, 29 April 2014 at 16:52:27 UTC, Ali Çehreli wrote: [...] int[] foo() { int[] a; a ~= 42;// on memory owned by the GC return a; } I didn't realize this was possible... I figured it was equivalent to `null ~= 42` which I realize now

Re: 'auto' with AA

2014-04-28 Thread David Held via Digitalmars-d-learn
On 4/27/2014 9:32 PM, Ali Çehreli wrote: fOn 04/27/2014 06:00 PM, David Held wrote: I would like to do something like this: Foo[Bar][Baz] nestedAA; auto innerAA = nestedAA[someBaz]; innerAA[someBar] = someFoo; assert(someFoo in nestedAA[someBaz]); in operator uses a key, not a

'auto' with AA

2014-04-27 Thread David Held via Digitalmars-d-learn
I would like to do something like this: Foo[Bar][Baz] nestedAA; auto innerAA = nestedAA[someBaz]; innerAA[someBar] = someFoo; assert(someFoo in nestedAA[someBaz]); Unfortunately, this does not do what I would like, because innerAA appears to be a copy rather than a reference. Is there a nice

toString() through interface

2014-04-19 Thread David Held via Digitalmars-d-learn
interface Foo { } class Bar : Foo { override string toString() pure const { return Bar; } } void main() { Foo foo = new Bar; foo.toString(); } src\Bug.d(14): Error: no property 'toString' for type 'Bug.Foo' Since all implementations of an interface must derive from Object, why

Re: toString() through interface

2014-04-19 Thread David Held via Digitalmars-d-learn
On 4/19/2014 5:35 PM, David Held wrote: interface Foo { } class Bar : Foo { override string toString() pure const { return Bar; } } void main() { Foo foo = new Bar; foo.toString(); } To make things more interesting, consider the call to toString() from inside a class (which

Re: Template method and type resolution of return type

2014-04-19 Thread David Held via Digitalmars-d-learn
On 4/19/2014 3:31 PM, Andrej Mitrovic via Digitalmars-d-learn wrote: [...] struct S { int get() { return 0; } T get(T)() { return T.init; } } void main() { S s; float x = s.get(); // which overload? (currently int get()) } Isn't this just because concrete methods are

Re: toString() through interface

2014-04-19 Thread David Held via Digitalmars-d-learn
On 4/19/2014 5:45 PM, Adam D. Ruppe wrote: On Sunday, 20 April 2014 at 00:35:30 UTC, David Held wrote: Since all implementations of an interface must derive from Object That's not true. They can also come from IUnknown or a C++ interface. Ok, that's a good reason!