Re: Question about generation of template functions

2019-08-29 Thread Machine Code via Digitalmars-d-learn
That's right, thank you all guys. Found my mistake; should be: serialize!(typeof(field))(__traits(getMember, output, fieldName));

Question about generation of template functions

2019-08-28 Thread Machine Code via Digitalmars-d-learn
I was writing a recursive function that uses template, I thought it would generate the proper template function on the fly to match the type in the parameter but it seems to not so so and try to use the called function, resulting in the error: Error: function foo.serialize!(B).serialize(ref B

Re: Sort Associative Array by Key

2019-08-27 Thread Machine Code via Digitalmars-d-learn
On Tuesday, 27 August 2019 at 16:25:00 UTC, Samir wrote: On Sunday, 25 August 2019 at 17:01:23 UTC, a11e99z wrote: auto foo = ["VXE":8, "BZP":5, "JLC":2]; foo.byPair.array.sort!"a[0] On Sunday, 25 August 2019 at 19:03:10 UTC, JN wrote: I think normal lambdas are better than these string ones:

Re: static variable A cannot be read at compile time

2019-06-12 Thread Machine Code via Digitalmars-d-learn
On Wednesday, 12 June 2019 at 14:09:08 UTC, Newbie2019 wrote: On Wednesday, 12 June 2019 at 13:53:09 UTC, H. S. Teoh wrote: On Wed, Jun 12, 2019 at 01:12:58PM +, Newbie2019 via Digitalmars-d-learn wrote: Read: https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time T

Re: Function parameters UDAs

2019-06-10 Thread Machine Code via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 02:24:49 UTC, Adam D. Ruppe wrote: On Tuesday, 11 June 2019 at 02:04:13 UTC, Machine Code wrote: I also, quite disappointed how UDAs doesn't work with enums. I end up using struct + enum to simulate that, sometimes it's quite a work. They do now... struct foo {}

Re: Function parameters UDAs

2019-06-10 Thread Machine Code via Digitalmars-d-learn
On Wednesday, 14 November 2018 at 16:28:19 UTC, Radu wrote: Looks like that there is no easy way to extract a function parameters UDA list. The following: ``` import std.traits; struct s { string foo; } void foo(@s("aaa") int a, bool x); void main() { alias P = Parameters!foo; enum

Re: Why this fails when using unittest?

2019-06-07 Thread Machine Code via Digitalmars-d-learn
On Friday, 7 June 2019 at 16:41:12 UTC, Adam D. Ruppe wrote: On Friday, 7 June 2019 at 16:33:13 UTC, Machine Code wrote: All this effort is because I do not want unittest code in a release or even debug. Well, that part is easy: version(unittest) struct Foo {} at any scope is only build

Re: Why this fails when using unittest?

2019-06-07 Thread Machine Code via Digitalmars-d-learn
On Friday, 7 June 2019 at 16:30:34 UTC, Machine Code wrote: On Thursday, 6 June 2019 at 21:02:37 UTC, Steven Schveighoffer wrote: [...] Intesting, I also tried to declare it inside a function, that did not work either. Is this hidden context pointer a current limitation in CTFE? I've tried

Re: Why this fails when using unittest?

2019-06-07 Thread Machine Code via Digitalmars-d-learn
On Thursday, 6 June 2019 at 21:02:37 UTC, Steven Schveighoffer wrote: On 6/6/19 1:49 PM, Adam D. Ruppe wrote: On Thursday, 6 June 2019 at 17:40:17 UTC, Machine Code wrote: outside an unittest, this compiles fine: struct A try making it `static struct` instead cannot implicitly convert

Re: Why this fails when using unittest?

2019-06-07 Thread Machine Code via Digitalmars-d-learn
On Thursday, 6 June 2019 at 17:49:58 UTC, Adam D. Ruppe wrote: On Thursday, 6 June 2019 at 17:40:17 UTC, Machine Code wrote: outside an unittest, this compiles fine: struct A try making it `static struct` instead didn't work either cannot implicitly convert expression "hehe" of

Re: Why this fails when using unittest?

2019-06-06 Thread Machine Code via Digitalmars-d-learn
On Thursday, 6 June 2019 at 17:40:17 UTC, Machine Code wrote: outside an unittest, this compiles fine: struct A { enum A foo = "hehe"; this(string a) { m_a = a; } alias m_a this; string m_a; } but if you

Why this fails when using unittest?

2019-06-06 Thread Machine Code via Digitalmars-d-learn
outside an unittest, this compiles fine: struct A { enum A foo = "hehe"; this(string a) { m_a = a; } alias m_a this; string m_a; } but if you wrap this a unittest {} and compile with dmd -unittest -run

Re: get executable version

2019-05-31 Thread Machine Code via Digitalmars-d-learn
On Friday, 31 May 2019 at 19:22:03 UTC, rikki cattermole wrote: On 01/06/2019 7:07 AM, Machine Code wrote: is there something on std library or package on dub to get a executable version on windows? just in case I don't need to dig into winapi. Like C#'s:

get executable version

2019-05-31 Thread Machine Code via Digitalmars-d-learn
is there something on std library or package on dub to get a executable version on windows? just in case I don't need to dig into winapi. Like C#'s: FileVersionInfo.GetVersionInfo(path).FileVersion

Re: [windows] Can't delete a closed file?

2019-05-10 Thread Machine Code via Digitalmars-d-learn
On Thursday, 9 May 2019 at 10:09:23 UTC, Cym13 wrote: Hi, this is likely not related to D itself but hopefully someone can help me with this since I'm rather new to windows programming, I mainly work on linux. I'm trying to bundle a DLL in a binary, write it in a temp folder, use it and

Re: How do I pass a template type as parameter?

2019-04-16 Thread Machine Code via Digitalmars-d-learn
On Tuesday, 16 April 2019 at 21:24:54 UTC, Adam D. Ruppe wrote: On Tuesday, 16 April 2019 at 21:07:51 UTC, Machine Code wrote: void f(appender!string buffer) { } appender isn't a type, it is a helper function that returns a type called Appender:

How do I pass a template type as parameter?

2019-04-16 Thread Machine Code via Digitalmars-d-learn
I've tried those syntaxes: void f(appender!string buffer) { } void f(A = appender)(A!string buffer) { } but no luck... how do I do that?

Re: default construction is disabled for type

2019-03-05 Thread Machine Code via Digitalmars-d-learn
So I find out the issue: it was due a struct member of the class having @disable this();

Re: default construction is disabled for type

2019-03-05 Thread Machine Code via Digitalmars-d-learn
public this() { } Doesn't change anything...

default construction is disabled for type

2019-03-05 Thread Machine Code via Digitalmars-d-learn
What's that error? below code used to work fine, now it gives this compiler error. class Keyword { this(string value, Token type) { this.value = value; this.type = type; } string value; Token type; Keyword next; }

Re: What's that 'q' before '{' in this code?

2019-01-15 Thread Machine Code via Digitalmars-d-learn
On Tuesday, 15 January 2019 at 17:56:10 UTC, SrMordred wrote: On Tuesday, 15 January 2019 at 17:52:35 UTC, Machine Code wrote: https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75 https://dlang.org/spec/lex.html#token_strings :) I had just infered from the commend in the code

What's that 'q' before '{' in this code?

2019-01-15 Thread Machine Code via Digitalmars-d-learn
https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75

Do I need to use static here?

2019-01-08 Thread Machine Code via Digitalmars-d-learn
I'm using enum to compute the value at runtime like this: struct A { enum foo = A("foo", 10); enum baa = A("baa", 20); string name; int value; alias value this; } In order to avoid foo having its value (even if literal) copied every time A instancied

Re: What's wrong with this template function?

2019-01-03 Thread Machine Code via Digitalmars-d-learn
On Thursday, 3 January 2019 at 21:41:44 UTC, Neia Neutuladh wrote: On Thu, 03 Jan 2019 20:34:17 +, Machine Code wrote: Thank you very much, Ali. So the issue was basically I can't return from a static foreach() loop right? The static foreach is done at compile time and the return is done

Re: What's wrong with this template function?

2019-01-03 Thread Machine Code via Digitalmars-d-learn
On Thursday, 3 January 2019 at 19:38:39 UTC, Ali Çehreli wrote: On 01/03/2019 10:49 AM, Machine Code wrote: > I wrote a small routine to return the first member I see that that's possible because the values of such members are known at compile time in your case. Otherwise, you would need a

What's wrong with this template function?

2019-01-03 Thread Machine Code via Digitalmars-d-learn
I wrote a small routine to return the first member of type T of a same type, like struct below, but the assert is reached albeit the "yes" message is printed. What am I missing? should I use something else than return keyword to return from a template function or what? struct Color {

Re: Are the below statements equivalent?

2018-12-27 Thread Machine Code via Digitalmars-d-learn
On Wednesday, 26 December 2018 at 18:03:44 UTC, Adam D. Ruppe wrote: On Wednesday, 26 December 2018 at 17:33:13 UTC, Machine Code wrote: Are the below statements equivalent? Yes, it is defined here: https://dlang.org/spec/statement.html#switch-statement (#2 in the list) Thanks!

Are the below statements equivalent?

2018-12-26 Thread Machine Code via Digitalmars-d-learn
Give: enum Foo { a, b, c, d, e } Foo f = Foo.c; Are the below statements equivalent? switch(f) { case Foo.a: case Foo.b: doSomething(); break; // ... } and: (note the comma in the case) switch(f) { case Foo.a, Foo.b: doSomething(); break; // ... } I found it