Can I use memoize with a non-static struct method?

2017-12-25 Thread Marc via Digitalmars-d-learn
something like this: struct S { // variables... string doGen(int n) { return ""; } alias gen = memoize!doGen; } The error I got is: Error: need 'this' for 'doGen' of type 'string(int n)' I can't make doGen static because it access non-static struct members... can I workaround this?

Re: What is 'scope' in function parameter?

2017-12-25 Thread Mike Franklin via Digitalmars-d-learn
On Monday, 25 December 2017 at 10:42:55 UTC, Sobaya wrote: ``` import std.stdio; int[] x; void func(scope int[] a) { x = a; } void main() { func([0,1,2]); writeln(x); } ``` This code was successfully compiled and printed '[0, 1, 2]'. But according to https://dlang.org/spec/funct

Re: Tail-constness of class parameters

2017-12-25 Thread Nordlöw via Digitalmars-d-learn
On Monday, 25 December 2017 at 15:16:55 UTC, ag0aep6g wrote: https://dlang.org/phobos/std_typecons.html#Rebindable Thanks.

Re: partial application for templates

2017-12-25 Thread David Nadlinger via Digitalmars-d-learn
On Monday, 25 December 2017 at 20:39:52 UTC, Mengu wrote: is partially applying templates possible? Check out std.meta.Apply{Left, Right}. — David

Re: Converting array in to aliased tuple type.

2017-12-25 Thread visitor via Digitalmars-d-learn
On Monday, 25 December 2017 at 21:35:18 UTC, visitor wrote: On Monday, 25 December 2017 at 21:11:08 UTC, aliak wrote: On Monday, 25 December 2017 at 17:59:54 UTC, visitor wrote: On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote: On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote:

Re: Converting array in to aliased tuple type.

2017-12-25 Thread visitor via Digitalmars-d-learn
On Monday, 25 December 2017 at 21:11:08 UTC, aliak wrote: On Monday, 25 December 2017 at 17:59:54 UTC, visitor wrote: On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote: On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote: I was kind of hoping for some magical D variadic alias tem

Re: Converting array in to aliased tuple type.

2017-12-25 Thread visitor via Digitalmars-d-learn
On Monday, 25 December 2017 at 17:59:54 UTC, visitor wrote: On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote: On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote: I was kind of hoping for some magical D variadic alias template on Tuple or something that will just deconstruct the

Re: Converting array in to aliased tuple type.

2017-12-25 Thread aliak via Digitalmars-d-learn
On Monday, 25 December 2017 at 17:59:54 UTC, visitor wrote: On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote: On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote: I was kind of hoping for some magical D variadic alias template on Tuple or something that will just deconstruct the

Re: partial application for templates

2017-12-25 Thread MrSmith via Digitalmars-d-learn
On Monday, 25 December 2017 at 20:39:52 UTC, Mengu wrote: is partially applying templates possible? template A(X, Y, Z) {} alias B(X, Y) = A!(X, Y, int);

partial application for templates

2017-12-25 Thread Mengu via Digitalmars-d-learn
is partially applying templates possible?

Curiously Recurring Template Pattern Example

2017-12-25 Thread helxi via Digitalmars-d-learn
Hi, Is there any blogs that discuss CRTP, or even Policy based/introspection based design in idiomatic D? I would love to see the strategies used to tackle the overhead involving dynamic dispatch by emulating static polymorphism. Thanks.

Re: DMD Windows 64bit target - how to setup the environment?

2017-12-25 Thread Andre Pany via Digitalmars-d-learn
On Monday, 25 December 2017 at 10:57:46 UTC, realhet wrote: Hello, I'm very well satisfied with the DMD 32bit compiler and the OptLink linker on Windows. I even made an incremental builder to it, and I can see the running program in 1 second. Lately I sadly noticed, that the OptLink works only

Re: DMD Windows 64bit target - how to setup the environment?

2017-12-25 Thread Benjamin Thaut via Digitalmars-d-learn
On Monday, 25 December 2017 at 16:35:26 UTC, realhet wrote: Now I have my first DMD 64bit windows console app running. (And I'm already afraid of the upcoming windowed application haha) My recommendation for getting setup on Windows with D is as follows: 1) Install the latest visual studio

Re: Define enum value at compile time via compiler argument?

2017-12-25 Thread Thomas Mader via Digitalmars-d-learn
On Monday, 25 December 2017 at 17:46:05 UTC, aliak wrote: On Monday, 25 December 2017 at 16:38:32 UTC, Thomas Mader wrote: On Monday, 25 December 2017 at 16:22:11 UTC, Mengu wrote: is it a relative path? if so: pragma(msg, __FILE_FULL_PATH__.split("/")[0..$-1].join("/")); https://run.d

Re: Converting array in to aliased tuple type.

2017-12-25 Thread visitor via Digitalmars-d-learn
On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote: On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote: I was kind of hoping for some magical D variadic alias template on Tuple or something that will just deconstruct the arguments in to tuple components. i don't think it's bette

Re: Define enum value at compile time via compiler argument?

2017-12-25 Thread aliak via Digitalmars-d-learn
On Monday, 25 December 2017 at 16:38:32 UTC, Thomas Mader wrote: On Monday, 25 December 2017 at 16:22:11 UTC, Mengu wrote: is it a relative path? if so: pragma(msg, __FILE_FULL_PATH__.split("/")[0..$-1].join("/")); https://run.dlang.io/is/gRUAD6 Nice idea but it is an absolute path. :

Re: DMD Windows 64bit target - how to setup the environment?

2017-12-25 Thread realhet via Digitalmars-d-learn
Now I have my first DMD 64bit windows console app running. (And I'm already afraid of the upcoming windowed application haha) After further fiddling I installed the >>>Visual Cpp tools 2015<<< package that contains a linker with x64 stuff in it (along with several GB of bloatware). contents

Re: Define enum value at compile time via compiler argument?

2017-12-25 Thread Thomas Mader via Digitalmars-d-learn
On Monday, 25 December 2017 at 16:22:11 UTC, Mengu wrote: is it a relative path? if so: pragma(msg, __FILE_FULL_PATH__.split("/")[0..$-1].join("/")); https://run.dlang.io/is/gRUAD6 Nice idea but it is an absolute path. :-/

Re: Define enum value at compile time via compiler argument?

2017-12-25 Thread Mengu via Digitalmars-d-learn
On Monday, 25 December 2017 at 16:13:48 UTC, Thomas Mader wrote: Hello, I would like to set the path to a directory at compile time but it doesn't seem to be possible yet. I tried it with a -version=CustomPath argument and inside the version statement in the code I tried to read the value fr

Define enum value at compile time via compiler argument?

2017-12-25 Thread Thomas Mader via Digitalmars-d-learn
Hello, I would like to set the path to a directory at compile time but it doesn't seem to be possible yet. I tried it with a -version=CustomPath argument and inside the version statement in the code I tried to read the value from the environment. Sadly this doesn't work because getenv can no

Re: Tail-constness of class parameters

2017-12-25 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 25 December 2017 at 14:49:11 UTC, Nordlöw wrote: 1. Is there a way to express tail-constness on the parameters https://dlang.org/phobos/std_typecons.html#Rebindable

Re: Converting array in to aliased tuple type.

2017-12-25 Thread aliak via Digitalmars-d-learn
On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote: since Point is a Tuple and does not have a constructor that takes a list of integers (int[]), you should have a helper function. Aukay :( I was kind of hoping for some magical D variadic alias template on Tuple or something that wil

Re: Does to!(string)(char[]) do any memory allocation on conversion?

2017-12-25 Thread aliak via Digitalmars-d-learn
On Monday, 25 December 2017 at 14:12:32 UTC, Marc wrote: Does to!(string)(char[]) do any memory allocation on conversion or is this similar to a cast or what else? As said it calls idup, which calls _trustedDup which seems to call _dup which does memory allocation -> https://github.com/dlang/

Tail-constness of class parameters

2017-12-25 Thread Nordlöw via Digitalmars-d-learn
In a graph library I'm working on I have the following algorithm bool hasContext(Node sub,// TODO in Node sup) nothrow // TODO in { Node curr = sub; while (true) { Node ctx = curr.context; if (!ctx) { break;} if (ctx is sup) retu

Re: Does to!(string)(char[]) do any memory allocation on conversion?

2017-12-25 Thread Temtaime via Digitalmars-d-learn
On Monday, 25 December 2017 at 14:37:01 UTC, Mengu wrote: On Monday, 25 December 2017 at 14:12:32 UTC, Marc wrote: Does to!(string)(char[]) do any memory allocation on conversion or is this similar to a cast or what else? yes, it is allocating memory. you can test such cases with @nogc [0].

Re: Does to!(string)(char[]) do any memory allocation on conversion?

2017-12-25 Thread Mengu via Digitalmars-d-learn
On Monday, 25 December 2017 at 14:12:32 UTC, Marc wrote: Does to!(string)(char[]) do any memory allocation on conversion or is this similar to a cast or what else? yes, it is allocating memory. you can test such cases with @nogc [0]. you can get a char[] via .dup of a string and then you can

Re: Does to!(string)(char[]) do any memory allocation on conversion?

2017-12-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 December 2017 at 14:37:01 UTC, Mengu wrote: yes, it is allocating memory. you can test such cases with @nogc [0]. nogc is really conservative and thus gives a lot of false positives. I'd just compare instr.ptr is outstr.ptr here and see if it changes (it will tho)

Re: Does to!(string)(char[]) do any memory allocation on conversion?

2017-12-25 Thread Temtaime via Digitalmars-d-learn
On Monday, 25 December 2017 at 14:12:32 UTC, Marc wrote: Does to!(string)(char[]) do any memory allocation on conversion or is this similar to a cast or what else? It is translated to idup. So yes, it allocates memory.

Does to!(string)(char[]) do any memory allocation on conversion?

2017-12-25 Thread Marc via Digitalmars-d-learn
Does to!(string)(char[]) do any memory allocation on conversion or is this similar to a cast or what else?

Re: Converting array in to aliased tuple type.

2017-12-25 Thread Mengu via Digitalmars-d-learn
On Monday, 25 December 2017 at 12:03:32 UTC, aliak wrote: Hi, been looking for a way to convert an array to a tuple, but can't seem to find one. Is there one? Looking for something like: alias Point = Tuple!(int, "x", int, "y"); enum data = "1,2:8,9"; auto points = data .split(':') .map!(a

Re: What is 'scope' in function parameter?

2017-12-25 Thread Mike Franklin via Digitalmars-d-learn
On Monday, 25 December 2017 at 11:09:25 UTC, Jonathan M Davis wrote: ``` import std.stdio; int[] x; void func(scope int[] a) { x = a; } void main() { func([0,1,2]); writeln(x); } ``` This code was successfully compiled and printed '[0, 1, 2]'. But according to https://dlang.

Converting array in to aliased tuple type.

2017-12-25 Thread aliak via Digitalmars-d-learn
Hi, been looking for a way to convert an array to a tuple, but can't seem to find one. Is there one? Looking for something like: alias Point = Tuple!(int, "x", int, "y"); enum data = "1,2:8,9"; auto points = data .split(':') .map!(a => a .split(',') .map!(to!int) ) .map!Point; /

Re: What is 'scope' in function parameter?

2017-12-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 25, 2017 10:42:55 Sobaya via Digitalmars-d-learn wrote: > What means 'scope' in function parameter? > > I made a test code. > > ``` > import std.stdio; > > int[] x; > > void func(scope int[] a) { > x = a; > } > > void main() { > func([0,1,2]); > writeln(x); > } >

Re: nested module problem

2017-12-25 Thread Jean-Louis Leroy via Digitalmars-d-learn
On Sunday, 24 December 2017 at 22:17:23 UTC, Luís Marques wrote: On Saturday, 2 September 2017 at 20:03:48 UTC, Jean-Louis Leroy wrote: jll@ORAC:~/dev/d/tests/modules$ tree . ├── foo │ └── bar.d └── foo.d I think that shouldn't be allowed. You have a package foo, but use a normal module ins

DMD Windows 64bit target - how to setup the environment?

2017-12-25 Thread realhet via Digitalmars-d-learn
Hello, I'm very well satisfied with the DMD 32bit compiler and the OptLink linker on Windows. I even made an incremental builder to it, and I can see the running program in 1 second. Lately I sadly noticed, that the OptLink works only for 32bit target, and I need to go to 64bit if I want to ha

What is 'scope' in function parameter?

2017-12-25 Thread Sobaya via Digitalmars-d-learn
What means 'scope' in function parameter? I made a test code. ``` import std.stdio; int[] x; void func(scope int[] a) { x = a; } void main() { func([0,1,2]); writeln(x); } ``` This code was successfully compiled and printed '[0, 1, 2]'. But according to https://dlang.org/spec/fu