Re: Issues using the in-line assembler

2018-04-04 Thread Basile B. via Digitalmars-d-learn
On Thursday, 5 April 2018 at 04:48:02 UTC, Basile B. wrote: On Wednesday, 4 April 2018 at 21:00:44 UTC, solidstate1991 wrote: void main() { import std.stdio; (new Foo).foo(0,0).writeln; } ``` Ah sorry, the params must be removed ((new Foo).foo().writeln;)... I was actually trying to

Re: Issues using the in-line assembler

2018-04-04 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 21:00:44 UTC, solidstate1991 wrote: I have this code: asm @nogc{ movqXMM0, xy; paddd XMM0, sXY; // xy + sXY movqXMM3, xy0; psubd XMM0, XMM3; // xy + sXY - x0y0 movq

Re: Construct immutable member in derived class

2018-04-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 04, 2018 21:46:13 Timoses via Digitalmars-d-learn wrote: > On Wednesday, 4 April 2018 at 18:11:12 UTC, Jonathan M Davis > > That code doesn't compile - at least not with dmd master. It > > gives these two errors: > > > > q.d(5): Error: constructor `q.A.this` missing initializer

Re: Declare and Define Before Use? [rant]

2018-04-04 Thread Rubn via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 20:01:55 UTC, Ali wrote: On Wednesday, 4 April 2018 at 19:51:27 UTC, kdevel wrote: On Wednesday, 4 April 2018 at 19:19:30 UTC, Ali wrote: BTW: You can't write void main () { x.writeln; int x; } import std.stdio; This is because x is not

Re: Better way to append to array than ~= ?

2018-04-04 Thread Jordan Wilson via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:02:25 UTC, Vladimirs Nordholm wrote: Hello people. I currently have a function which multiple times per second takes in arguments, and appends the argument as my special type. The following code should explain what I do more properly: struct MySpecialType

Re: Construct immutable member in derived class

2018-04-04 Thread Timoses via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 16:16:24 UTC, Alex wrote: Here is something: https://dlang.org/spec/class.html#constructors By the rules 7 and 8 it is suggested, what Simen already said, the construction of the base class can be independent from the derived one. And as such, the immutability

Re: Construct immutable member in derived class

2018-04-04 Thread Timoses via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 18:11:12 UTC, Jonathan M Davis wrote: On Wednesday, April 04, 2018 16:05:52 Timoses via ``` class A { immutable int i; this(){} } class B : A { this() { this.i = 3; super(); // <- specifically calling

Re: Issues using the in-line assembler

2018-04-04 Thread solidstate1991 via Digitalmars-d-learn
I forgot to tell, that xy0 ac, and bd are local to the class.

Issues using the in-line assembler

2018-04-04 Thread solidstate1991 via Digitalmars-d-learn
I have this code: asm @nogc{ movqXMM0, xy; paddd XMM0, sXY; // xy + sXY movqXMM3, xy0; psubd XMM0, XMM3; // xy + sXY - x0y0 movqXMM1, ac; movqXMM2, bd; pmuludq

Re: Declare and Define Before Use? [rant]

2018-04-04 Thread Cym13 via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 19:51:27 UTC, kdevel wrote: On Wednesday, 4 April 2018 at 19:19:30 UTC, Ali wrote: On Wednesday, 4 April 2018 at 18:57:27 UTC, kdevel wrote: [...] I think the rules should have been the same everywhere and if there was an exception to be made, it could be made for

Re: Declare and Define Before Use? [rant]

2018-04-04 Thread Ali via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 19:51:27 UTC, kdevel wrote: On Wednesday, 4 April 2018 at 19:19:30 UTC, Ali wrote: BTW: You can't write void main () { x.writeln; int x; } import std.stdio; This is because x is not module scope you can do this void main () {

Re: how to set up libuid on wondows 10

2018-04-04 Thread bauss via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 19:10:33 UTC, greatsam4sure wrote: I am have problem setting up libuid on windows 10. These are the errors thus far: [...] How do you call the compiler? Make sure you pass all the libraries etc. to dmd when you compile.

Re: Declare and Define Before Use? [rant]

2018-04-04 Thread kdevel via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 19:19:30 UTC, Ali wrote: On Wednesday, 4 April 2018 at 18:57:27 UTC, kdevel wrote: [...] I think the rules should have been the same everywhere and if there was an exception to be made, it could be made for the main function since the main function is special

Re: Declare and Define Before Use? [rant]

2018-04-04 Thread Ali via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 18:57:27 UTC, kdevel wrote: Why are people writing import std.stdio; void main () { } struct S { } but not void main () { } struct S { } import std.stdio; ? Personally i found it weird and inconsistent that

how to set up libuid on wondows 10

2018-04-04 Thread greatsam4sure via Digitalmars-d-learn
I am have problem setting up libuid on windows 10. These are the errors thus far: C:\Users\Greatsam\Desktop\HelloApp>dub Fetching libuid 0.0.7 (getting selected version)... Performing "debug" build using dmd for x86. libuid 0.0.7: building configuration "lib"... helloapp ~master: building

Declare and Define Before Use? [rant]

2018-04-04 Thread kdevel via Digitalmars-d-learn
Why are people writing import std.stdio; void main () { S s; s.foo; } struct S { void foo () { writeln ("a"); } } but not void main () { S s; s.foo; } struct S { void foo () { writeln

Re: Optional parameters?

2018-04-04 Thread Dukc via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 15:44:34 UTC, Steven Schveighoffer wrote: See my original post: I know I can do things like this: void foo(int x) { return foo(nullable(x)); } -Steve Oops, I read only the body of that function and thought it's a main function constructiong nullable when

Re: Construct immutable member in derived class

2018-04-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 04, 2018 16:05:52 Timoses via Digitalmars-d-learn wrote: > On Wednesday, 4 April 2018 at 10:41:52 UTC, Simen Kjærås wrote: > > Because by the time B's constructor is called, A might already > > have initialized it, and rely on it never changing. > > What about: > > ``` > class

Re: Construct immutable member in derived class

2018-04-04 Thread Alex via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 16:05:52 UTC, Timoses wrote: This becomes a bit hideous, unfortunately, when there are many initializations involved. Found this, but it doesn't mention anything about derived classes.. https://dlang.org/spec/class.html#field-init Here is something:

Re: Construct immutable member in derived class

2018-04-04 Thread Timoses via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 10:41:52 UTC, Simen Kjærås wrote: Because by the time B's constructor is called, A might already have initialized it, and rely on it never changing. What about: ``` class A { immutable int i; this(){} } class B : A { this() { this.i = 3;

Re: Get the type of 'alias this ='

2018-04-04 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 15:57:19 UTC, Simen Kjærås wrote: On Wednesday, 4 April 2018 at 15:49:31 UTC, Vladimirs Nordholm wrote: if (is(T == A) || is(T == B) || is(T == Enum)) if (is(T : Enum)) -- Simen Ah! Thanks a lot!

Re: Get the type of 'alias this ='

2018-04-04 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 15:49:31 UTC, Vladimirs Nordholm wrote: private template Mix() { this(Enum ee) { e = ee; } Enum e; alias this = e; } Oops, typo in the alias. Should be `alias e this`

Re: Get the type of 'alias this ='

2018-04-04 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 15:49:31 UTC, Vladimirs Nordholm wrote: if (is(T == A) || is(T == B) || is(T == Enum)) if (is(T : Enum)) -- Simen

Re: Better way to append to array than ~= ?

2018-04-04 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 20:41:01 UTC, Alex wrote: On Tuesday, 3 April 2018 at 20:02:46 UTC, Vladimirs Nordholm wrote: On Tuesday, 3 April 2018 at 19:53:11 UTC, Meta wrote: [...] I don't think I know the size of the arguments. If I pass in "123" and MySpecialType('a'), the result should

Get the type of 'alias this ='

2018-04-04 Thread Vladimirs Nordholm via Digitalmars-d-learn
Hello people from D-land. Short question: Can get the type of a struct that has `alias this = ` ? See this example, where a struct is aliased to an enum: enum Enum { one, two, three, fourtytwo } private template Mix() { this(Enum ee) { e = ee; } Enum e;

Re: Optional parameters?

2018-04-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/4/18 8:59 AM, Dukc wrote: Is this what you're looking for? See my original post: I know I can do things like this: void foo(int x) { return foo(nullable(x)); } -Steve

Re: Taming templates and mixin magic: type inpector helper in D/Phobos?

2018-04-04 Thread Uknown via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 05:28:57 UTC, Carlos Navarro wrote: As a newbie in D (and making a lots of mistakes), I've found myself relying heavily in the use of a rudimentary type inspector to visualize my templated code instantiations. It's simple and incomplete as hell but good enough to

Re: Optional parameters?

2018-04-04 Thread Dukc via Digitalmars-d-learn
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer wrote: But I'd rather avoid such things if possible. Is there a way around this? Seems rather limiting that I can do: Is this what you're looking for? void foo(Nullable!int x = Nullable!int.init) { if (!x.isNull) x.get.writeln;

Re: Strange behavior using array of structures

2018-04-04 Thread Orfeo via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 10:09:41 UTC, sarn wrote: On Wednesday, 4 April 2018 at 10:00:18 UTC, Orfeo wrote: foreach (l; log) { l.run; } Try making this "foreach (ref l; log) {". Structs are value types in D, so by default they're copied when you assign them to

Re: Construct immutable member in derived class

2018-04-04 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 10:11:37 UTC, Timoses wrote: Example: ``` class A { immutable int i; this(){} } class B : A { this() { this.i = 3; } } void main() { auto b = new B; } ``` throws: Error: constructor `onlineapp.A.this` missing initializer for

Construct immutable member in derived class

2018-04-04 Thread Timoses via Digitalmars-d-learn
Example: ``` class A { immutable int i; this(){} } class B : A { this() { this.i = 3; } } void main() { auto b = new B; } ``` throws: Error: constructor `onlineapp.A.this` missing initializer for immutable field i Error: cannot modify immutable expression

Re: Strange behavior using array of structures

2018-04-04 Thread sarn via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 10:00:18 UTC, Orfeo wrote: foreach (l; log) { l.run; } Try making this "foreach (ref l; log) {". Structs are value types in D, so by default they're copied when you assign them to another variable (in this case l). That means run() is

Strange behavior using array of structures

2018-04-04 Thread Orfeo via Digitalmars-d-learn
Hi all, I have: ``` import std.stdio; void main() { Logger[] log; Logger l0 = Logger(0,1); Logger l1 = Logger(100,1); Logger l2 = Logger(200,1); log ~= l0; log ~= l1; foreach (i; 0 .. 3) { writeln("it:", i); foreach (l; log) { l.run; } } }

Re: Optional parameters?

2018-04-04 Thread Timoses via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 08:08:40 UTC, Dejan Lekic wrote: On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer wrote: I currently have a situation where I want to have a function that accepts a parameter optionally. This is what function overloading and/or default values are

Re: Optional parameters?

2018-04-04 Thread Dejan Lekic via Digitalmars-d-learn
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer wrote: I currently have a situation where I want to have a function that accepts a parameter optionally. This is what function overloading and/or default values are for, right?