Best ways to declare associative arrays

2017-03-12 Thread helxi via Digitalmars-d-learn
How would an experienced programmer declare an associative array of strings that has 2 keys? My initial impression was string[string][2] my_array; which does not seem to work. Here is a snippet of the code I am working on: import std.string; import std.stdio; string[string] change(ref str

Re: Best ways to declare associative arrays

2017-03-12 Thread helxi via Digitalmars-d-learn
On Sunday, 12 March 2017 at 07:58:40 UTC, helxi wrote: return def; I meant return arg_array;

Re: Best ways to declare associative arrays

2017-03-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 12 March 2017 at 07:58:40 UTC, helxi wrote: How would an experienced programmer declare an associative array of strings that has 2 keys? My initial impression was string[string][2] my_array; which does not seem to work. Here is a snippet of the code I am working on: import std.s

Code style for property

2017-03-12 Thread Andrey via Digitalmars-d-learn
Hello, how better to declare properties, for example I have class: class Foo { this(in int x, in int y, Bar bar) { this.x = x; this.y = y; this.bar = bar; } private: int x; int y; Bar bar; } And I want make access to read x, y and bar. Probably I should

Re: Code style for property

2017-03-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 12 March 2017 at 10:47:35 UTC, Andrey wrote: Hello, how better to declare properties, for example I have class: class Foo { this(in int x, in int y, Bar bar) { this.x = x; this.y = y; this.bar = bar; } private: int x; int y; Bar bar; } And I

GDC options

2017-03-12 Thread Russel Winder via Digitalmars-d-learn
Hi, ldc2 has the -unittest --main options to compile a file that has unittests and no main so as to create a test executable. What causes the same behaviour with gdc? -- Russel. = Dr Russel Winder t: +44 20 7585 220

Re: Best ways to declare associative arrays

2017-03-12 Thread XavierAP via Digitalmars-d-learn
On Sunday, 12 March 2017 at 07:58:40 UTC, helxi wrote: string[string] change(ref string[string] arg_array){ //.. arg_array["first"] = strip(readln()); //.. arg_array["second"] = strip(readln()); //.. return def; } Nicholas clarified why your decl

Re: Code style for property

2017-03-12 Thread XavierAP via Digitalmars-d-learn
On Sunday, 12 March 2017 at 11:15:04 UTC, Nicholas Wilson wrote: On Sunday, 12 March 2017 at 10:47:35 UTC, Andrey wrote: And I want make access to read x, y and bar. Probably I should add prefix for private members, that is a question: what prefix should I use? Now I use prefix p_ (from the wor

Re: Code style for property

2017-03-12 Thread Andrey via Digitalmars-d-learn
On Sunday, 12 March 2017 at 11:15:04 UTC, Nicholas Wilson wrote: You should only declare getters/setters if you need to (or think you may need to later) intercept the assignment or acquisition of a variable (logging, computing on demand) have a field as externally read only (setter

Re: GDC options

2017-03-12 Thread Johannes Pfau via Digitalmars-d-learn
Am Sun, 12 Mar 2017 12:09:01 + schrieb Russel Winder via Digitalmars-d-learn : > Hi, > > ldc2 has the -unittest --main options to compile a file that has > unittests and no main so as to create a test executable. What causes > the same behaviour with gdc? > https://github.com/D-Programming-

Re: Code style for property

2017-03-12 Thread Stefan via Digitalmars-d-learn
On Sunday, 12 March 2017 at 10:47:35 UTC, Andrey wrote: Hello, how better to declare properties, for example I have class: class Foo { this(in int x, in int y, Bar bar) { this.x = x; this.y = y; this.bar = bar; } private: int x; int y; Bar bar; } And

Template specialisation for range of types

2017-03-12 Thread data pulverizer via Digitalmars-d-learn
Hello all, I am attempting to write templates for differently qualified types using specialisations. Below is an example for const and non-const outlining my approach: `` import std.stdio : writeln; import std.traits : ConstOf; auto max(T)(T x, T y) { writeln

Re: Template specialisation for range of types

2017-03-12 Thread Jerry via Digitalmars-d-learn
On Sunday, 12 March 2017 at 18:49:22 UTC, data pulverizer wrote: Hello all, I am attempting to write templates for differently qualified types using specialisations. Below is an example for const and non-const outlining my approach: `` import std.stdio : writeln; imp

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
data pulverizer wrote: In this case would like to use the ConstOf specialisation instead of the default implementation for the inputs which are const. actually, second template is uninstantiable at all. you want to do type deconstruction at instantiation, and that doesn't work. i.e. what yo

Re: Template specialisation for range of types

2017-03-12 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 12 March 2017 at 19:32:37 UTC, ketmar wrote: data pulverizer wrote: In this case would like to use the ConstOf specialisation instead of the default implementation for the inputs which are const. actually, second template is uninstantiable at all. you want to do type deconstructi

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
data pulverizer wrote: If I change the implementation of the second template to your above declaration, I get the error: max.max called with argument types (const(double)*, const(double)*) matches both: max.d(34): max.max!(const(double)*).max(const(double)* x, const(double)* y) and: max

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
data pulverizer wrote: I need at least those two implementation for the different cases, a general "default", and for specified types and type qualifications. p.s.: if you want that to work with both pointers and non-pointers, you have to add more constraints, to remove further conflicts.

Re: Code style for property

2017-03-12 Thread Andrey via Digitalmars-d-learn
On Sunday, 12 March 2017 at 17:50:41 UTC, Stefan wrote: On Sunday, 12 March 2017 at 10:47:35 UTC, Andrey wrote: Hello, how better to declare properties, for example I have class: class Foo { this(in int x, in int y, Bar bar) { this.x = x; this.y = y; this.bar = bar;

Re: Template specialisation for range of types

2017-03-12 Thread Meta via Digitalmars-d-learn
On Sunday, 12 March 2017 at 18:49:22 UTC, data pulverizer wrote: Hello all, I am attempting to write templates for differently qualified types using specialisations. Below is an example for const and non-const outlining my approach: `` import std.stdio : writeln; imp

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
Meta wrote: The reason this doesn't work is when you use ConstOf!U, it's not looking for a `const U`, it's looking for the type `ConstOf!U`. I'm not sure if this is a bug or not... no, not a bug. this is the way type deconstruction works: it checks if your type was constructed with a given t

Re: Template specialisation for range of types

2017-03-12 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 12 March 2017 at 20:15:43 UTC, Meta wrote: import std.stdio : writeln; import std.traits : ConstOf; auto max(T)(T x, T y) { writeln("General template"); return x > y ? x : y; } auto max(T: const U, U)(T* x, T* y) <- Changed `ConstOf!U` to `const U` { w

Re: Template specialisation for range of types

2017-03-12 Thread Meta via Digitalmars-d-learn
On Sunday, 12 March 2017 at 20:22:33 UTC, ketmar wrote: Meta wrote: The reason this doesn't work is when you use ConstOf!U, it's not looking for a `const U`, it's looking for the type `ConstOf!U`. I'm not sure if this is a bug or not... no, not a bug. this is the way type deconstruction work

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
Meta wrote: On Sunday, 12 March 2017 at 20:22:33 UTC, ketmar wrote: Meta wrote: The reason this doesn't work is when you use ConstOf!U, it's not looking for a `const U`, it's looking for the type `ConstOf!U`. I'm not sure if this is a bug or not... no, not a bug. this is the way type decon

Re: Template specialisation for range of types

2017-03-12 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 12 March 2017 at 20:15:43 UTC, Meta wrote: auto max(T: const U, U)(T* x, T* y) <- Changed `ConstOf!U` to `const U` { writeln("Const template"); return *x > *y ? x : y; } How detailed can I be about the template specialisation? From example in the book "C++ the com

scope(~this)

2017-03-12 Thread Inquie via Digitalmars-d-learn
Is there any easy way to create a scope for termination of the object? I have a template method that takes a type and allocates and deallocates based on that type. class bar { void foo(T)() { T x; alloc(x); scope(~this) dealloc(x); // hypothetical that wraps the state

Re: scope(~this)

2017-03-12 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 12 March 2017 at 21:38:44 UTC, Inquie wrote: Is there any easy way to create a scope for termination of the object? [...] scope(exit)

Re: scope(~this)

2017-03-12 Thread Inquie via Digitalmars-d-learn
On Sunday, 12 March 2017 at 22:13:21 UTC, Stefan Koch wrote: On Sunday, 12 March 2017 at 21:38:44 UTC, Inquie wrote: Is there any easy way to create a scope for termination of the object? [...] scope(exit) That is for the function, correct? If I release the resource at the end of the func

how to assign tuple named Tuple easily

2017-03-12 Thread Inquie via Digitalmars-d-learn
Tuple!(int, "A") x; x = tuple(3); fails of course x = tuple!("A")(3); Works but specifying the name seems to be redundant. Can we simplify for the more complex case? e.g., x = tuple!(GetTypleNames!x)(3); which should then be possible to simplify even further to x = tuple(3); or, rather

Re: how to assign tuple named Tuple easily

2017-03-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 12 March 2017 at 23:16:48 UTC, Inquie wrote: Tuple!(int, "A") x; x = tuple(3); fails of course umm it works for me...

Re: how to assign tuple named Tuple easily

2017-03-12 Thread Inquie via Digitalmars-d-learn
On Sunday, 12 March 2017 at 23:55:44 UTC, Adam D. Ruppe wrote: On Sunday, 12 March 2017 at 23:16:48 UTC, Inquie wrote: Tuple!(int, "A") x; x = tuple(3); fails of course umm it works for me... Ok, it doesn't work for appending though ;) Tuple!(int, "A", double, "B")[] y; y ~= tuple!("A", "

Re: how to assign tuple named Tuple easily

2017-03-12 Thread ag0aep6g via Digitalmars-d-learn
On 03/13/2017 01:02 AM, Inquie wrote: Ok, it doesn't work for appending though ;) [...] Tuple!(int, "A", double, "B")[] y; y ~= tuple(3, 2.5); Interestingly, this works: Tuple!(int, "A", double, "B")[] y; y.length += 1; y[$ - 1] = tuple(3, 2.5);

Re: how to assign tuple named Tuple easily

2017-03-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 13 March 2017 at 00:02:12 UTC, Inquie wrote: I just figured it didn't work in general, but seems to be an issue with appending. Oh, it is because of the implicit construction thing, see my answer here to learn more: http://stackoverflow.com/a/42285015/1457000 You can construct th

Re: Template specialisation for range of types

2017-03-12 Thread Meta via Digitalmars-d-learn
On Sunday, 12 March 2017 at 21:12:13 UTC, data pulverizer wrote: On Sunday, 12 March 2017 at 20:15:43 UTC, Meta wrote: auto max(T: const U, U)(T* x, T* y) <- Changed `ConstOf!U` to `const U` { writeln("Const template"); return *x > *y ? x : y; } How detailed can I be about t

Declaring interfaces with a constructor

2017-03-12 Thread David Zhang via Digitalmars-d-learn
What it says on the tin. Is there a way to create interfaces with a constructor or must I use an abstract class. Additionally, is there a way to force the linker to link a function in a class without an implementation with another that does have an implementation? i.e. --- //module a;

Re: scope(~this)

2017-03-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 12 March 2017 at 21:38:44 UTC, Inquie wrote: Is there any easy way to create a scope for termination of the object? I have a template method that takes a type and allocates and deallocates based on that type. class bar { void foo(T)() { T x; alloc(x); scope

Re: Can i using D & LLVM & SDL2 for Android?

2017-03-12 Thread Joakim via Digitalmars-d-learn
On Thursday, 9 March 2017 at 10:35:18 UTC, dummy wrote: On Wednesday, 8 March 2017 at 10:24:24 UTC, Joakim wrote: On Tuesday, 7 March 2017 at 12:06:48 UTC, dummy wrote: Just thought. I do want to know. :-) As far as I know is, * LDC2 woring on NDK(yah!) * Native OpenGLES: http://wiki.dlan