alias this and initialisation

2020-05-24 Thread Danni Coy via Digitalmars-d-learn
can anybody tell me why struct S { int x; alias x this; } void test() { S s; s = 8; // this works S s = 8 // but this does not? }

m32mscoff with lld-link causes SEH errors

2020-05-24 Thread Daniel C via Digitalmars-d-learn
Hi, I have a simple program with just one line (below). I've compiled on Windows using dmd -ms32coff app.d and have had LINKCMD set to lld-link, but get the following errors. Is lld-link only for 64-bit compiles (-m64 is the only one that gives no errors) lld-link: error: /safeseh: app.obj

Re: How to flatten N-dimensional array?

2020-05-24 Thread Ali Çehreli via Digitalmars-d-learn
On 5/24/20 2:37 AM, Pavel Shkadzko wrote: On Saturday, 23 May 2020 at 19:59:30 UTC, Ali Çehreli wrote: On 5/23/20 11:15 AM, Pavel Shkadzko wrote:> I have tried to implement a simple flatten function for multidimensional [...] Thank you, I was lacking practical examples for templates with

Re: Static assert triggered in struct constructor that shouldn't be called

2020-05-24 Thread jmh530 via Digitalmars-d-learn
On Sunday, 24 May 2020 at 21:43:34 UTC, H. S. Teoh wrote: On Sun, May 24, 2020 at 09:34:53PM +, jmh530 via Digitalmars-d-learn wrote: The following code results in the static assert in the constructor being triggered, even though I would have thought no constructor would have been called.

Re: Static assert triggered in struct constructor that shouldn't be called

2020-05-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 24 May 2020 at 21:34:53 UTC, jmh530 wrote: The following code results in the static assert in the constructor being triggered, even though I would have thought no constructor would have been called. static assert is triggered when the code is *compiled*, whether it is actually run

Re: Static assert triggered in struct constructor that shouldn't be called

2020-05-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 24, 2020 at 09:34:53PM +, jmh530 via Digitalmars-d-learn wrote: > The following code results in the static assert in the constructor > being triggered, even though I would have thought no constructor would > have been called. I know that there is an easy fix for this (move the >

Static assert triggered in struct constructor that shouldn't be called

2020-05-24 Thread jmh530 via Digitalmars-d-learn
The following code results in the static assert in the constructor being triggered, even though I would have thought no constructor would have been called. I know that there is an easy fix for this (move the static if outside the constructor), but it still seems like it doesn't make sense.

Re: RtlAdjustPrivilege and NtRaiseHardError

2020-05-24 Thread novice2 via Digitalmars-d-learn
"doesn't work" isn't very helpful. Are you seeing compiler errors? Linker errors? Runtime errors? Please describe your problem. Solved my problem alone : wrong signatures with functions ;) and this reply isn't very helpful. what is right signature? you go to forum to ask help. but wish you

Re: RtlAdjustPrivilege and NtRaiseHardError

2020-05-24 Thread Arsium via Digitalmars-d-learn
On Saturday, 23 May 2020 at 01:33:13 UTC, Mike Parker wrote: On Friday, 22 May 2020 at 19:19:19 UTC, Arsium wrote: Just I tried to launch those functions from win32 api and seems doesn't work "doesn't work" isn't very helpful. Are you seeing compiler errors? Linker errors? Runtime errors?

Re: Mir Slice.shape is not consistent with the actual array shape

2020-05-24 Thread Pavel Shkadzko via Digitalmars-d-learn
On Sunday, 24 May 2020 at 15:24:14 UTC, 9il wrote: On Sunday, 24 May 2020 at 14:17:33 UTC, Pavel Shkadzko wrote: [...] BTW, the code example above doesn't compiles. OT: Instead of [...] you can generate the same common D array using Mir: auto a = [2, 2, 4].iota!int(1).ndarray;

Re: How to get the pointer of "this" ?

2020-05-24 Thread bauss via Digitalmars-d-learn
On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: Hi all, I have a class like this. class Button : Control { ... HWND createButton(){ ... SetWindowSubclass(this.mHandle, SUBCLASSPROC(), UINT_PTR(subClsID), cast(DWORD_PTR) this); } } But

Re: Variable "i" can not be read at compile time

2020-05-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.05.20 19:13, data pulverizer wrote: Thank you very much. I though that if I used a `static foreach` loop D would attempt to run the calculation `bench()` at compile time rather than at run time but it doesn't which is good. So `static foreach` allows you to index at compile time and if

Re: Variable "i" can not be read at compile time

2020-05-24 Thread bauss via Digitalmars-d-learn
On Sunday, 24 May 2020 at 17:13:23 UTC, data pulverizer wrote: On Sunday, 24 May 2020 at 16:57:54 UTC, ag0aep6g wrote: On 24.05.20 18:34, data pulverizer wrote: Since `kernel` is a `Tuple`, you can only access it with compile-time constant indices. But your loop variable `i` is not a

Re: Variable "i" can not be read at compile time

2020-05-24 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 24 May 2020 at 16:57:54 UTC, ag0aep6g wrote: On 24.05.20 18:34, data pulverizer wrote: Since `kernel` is a `Tuple`, you can only access it with compile-time constant indices. But your loop variable `i` is not a compile-time constant, it's being calculated at run time. What's more,

How to get the pointer of "this" ?

2020-05-24 Thread Vinod K Chandran via Digitalmars-d-learn
Hi all, I have a class like this. class Button : Control { ... HWND createButton(){ ... SetWindowSubclass(this.mHandle, SUBCLASSPROC(), UINT_PTR(subClsID), cast(DWORD_PTR) this); } } But compiler says that - "Error: 'this' is not an lvalue and cannot

Re: Variable "i" can not be read at compile time

2020-05-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.05.20 18:34, data pulverizer wrote: I'm getting the error: ``` Error: variable i cannot be read at compile time Error: template instance script.runKernelBenchmarks!(Tuple!(DotProduct!float, Gaussian!float, Polynomial!float, Exponential!float, Log!float, Cauchy!float, Power!float,

Variable "i" can not be read at compile time

2020-05-24 Thread data pulverizer via Digitalmars-d-learn
Hi all, I'm getting the error: ``` Error: variable i cannot be read at compile time Error: template instance script.runKernelBenchmarks!(Tuple!(DotProduct!float, Gaussian!float, Polynomial!float, Exponential!float, Log!float, Cauchy!float, Power!float, Wave!float, Sigmoid!float)) error

Re: Using Vibe.d for not HTTP

2020-05-24 Thread Panke via Digitalmars-d-learn
On Sunday, 24 May 2020 at 16:14:58 UTC, Russel Winder wrote: On Sun, 2020-05-24 at 17:01 +0100, Russel Winder wrote: […] connection.read(buffer, IOMode.once); What an idiot I am, this call returns the read count, which makes it fine. Progress now being made. I had a look. Documentation

Re: Using Vibe.d for not HTTP

2020-05-24 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2020-05-24 at 17:01 +0100, Russel Winder wrote: > […] > connection.read(buffer, IOMode.once); > What an idiot I am, this call returns the read count, which makes it fine. Progress now being made. -- Russel. === Dr Russel Winder t: +44 20

Re: Using Vibe.d for not HTTP

2020-05-24 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2020-05-24 at 12:26 +, bauss via Digitalmars-d-learn wrote: […] Thanks for responding, much appreciated. > void handleConnections(TCPConnection connection) { > ... > } I guess I was looking for an example of what to put in this function! > auto buf = new ubyte[amount]; > >

Re: Mir Slice.shape is not consistent with the actual array shape

2020-05-24 Thread 9il via Digitalmars-d-learn
On Sunday, 24 May 2020 at 14:17:33 UTC, Pavel Shkadzko wrote: I am confused by the return value of Mir shape. Consider the following example. /// import std.stdio; import std.conv; import std.array: array; import std.range:

Re: Mir Slice.shape is not consistent with the actual array shape

2020-05-24 Thread Pavel Shkadzko via Digitalmars-d-learn
On Sunday, 24 May 2020 at 14:35:33 UTC, jmh530 wrote: On Sunday, 24 May 2020 at 14:21:26 UTC, Pavel Shkadzko wrote: [snip] Sorry for the typo. It should be "auto arrSlice = a.sliced;" Try using fuse /+dub.sdl: dependency "mir-algorithm" version="*" +/ import std.stdio; import std.conv;

Re: Mir Slice.shape is not consistent with the actual array shape

2020-05-24 Thread 9il via Digitalmars-d-learn
On Sunday, 24 May 2020 at 14:17:33 UTC, Pavel Shkadzko wrote: I am confused by the return value of Mir shape. Consider the following example. [...] `sliced` returns a view on the array data, a 1-dimensional slice composed of common D arrays. Try to use `fuse` instead of `sliced`.

Re: Mir Slice.shape is not consistent with the actual array shape

2020-05-24 Thread Pavel Shkadzko via Digitalmars-d-learn
On Sunday, 24 May 2020 at 14:21:26 UTC, Pavel Shkadzko wrote: On Sunday, 24 May 2020 at 14:17:33 UTC, Pavel Shkadzko wrote: I am confused by the return value of Mir shape. Consider the following example. [...] Sorry for the typo. It should be "auto arrSlice = a.sliced;" And another typo

Re: Mir Slice.shape is not consistent with the actual array shape

2020-05-24 Thread jmh530 via Digitalmars-d-learn
On Sunday, 24 May 2020 at 14:21:26 UTC, Pavel Shkadzko wrote: [snip] Sorry for the typo. It should be "auto arrSlice = a.sliced;" Try using fuse /+dub.sdl: dependency "mir-algorithm" version="*" +/ import std.stdio; import std.conv; import std.array: array; import std.range: chunks; import

Re: Mir Slice.shape is not consistent with the actual array shape

2020-05-24 Thread Pavel Shkadzko via Digitalmars-d-learn
On Sunday, 24 May 2020 at 14:17:33 UTC, Pavel Shkadzko wrote: I am confused by the return value of Mir shape. Consider the following example. [...] Sorry for the typo. It should be "auto arrSlice = a.sliced;"

Mir Slice.shape is not consistent with the actual array shape

2020-05-24 Thread Pavel Shkadzko via Digitalmars-d-learn
I am confused by the return value of Mir shape. Consider the following example. /// import std.stdio; import std.conv; import std.array: array; import std.range: chunks; import mir.ndslice; int[] getShape(T : int)(T obj,

Re: Distinguish between a null array and an empty array

2020-05-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.05.20 14:29, bauss wrote: Dang, that sucks there is no proper way and I would say that's a big flaw of D. Because what I need it for is for some data serialization but if the value is an empty array then it should be present and if it's null then it should not be present. Since null

Re: Distinguish between a null array and an empty array

2020-05-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.05.20 14:12, bauss wrote: Is there a way to do that? Since the following are both true: int[] a = null; int[] b = []; assert(a is null); assert(!a.length); assert(b is null); assert(!b.length); What I would like is to tell that b is an empty array and a is a null array. No way.

Re: Distinguish between a null array and an empty array

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 24, 2020 6:12:31 AM MDT bauss via Digitalmars-d-learn wrote: > Is there a way to do that? > > Since the following are both true: > > int[] a = null; > int[] b = []; > > assert(a is null); > assert(!a.length); > > assert(b is null); > assert(!b.length); > > What I would like is to

Re: Using Vibe.d for not HTTP

2020-05-24 Thread bauss via Digitalmars-d-learn
On Sunday, 24 May 2020 at 08:10:33 UTC, Russel Winder wrote: Hi, Clearly Vibe.d is mostly for people doing HTTP and HTTPS stuff. Yet it claims to be able to support TCP and UDP working with other protocols. However, all the serious examples are HTTP/HTTPS related. All the TCP and UDP

Re: Distinguish between a null array and an empty array

2020-05-24 Thread bauss via Digitalmars-d-learn
On Sunday, 24 May 2020 at 12:26:42 UTC, ag0aep6g wrote: On 24.05.20 14:12, bauss wrote: Is there a way to do that? Since the following are both true: int[] a = null; int[] b = []; assert(a is null); assert(!a.length); assert(b is null); assert(!b.length); What I would like is to tell that

Re: opEquals @safe is ignored

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 24, 2020 2:57:28 AM MDT Luis via Digitalmars-d-learn wrote: > Lets take this example code (https://run.dlang.io/is/Vkpx9j) : > > ´´´D > import std; > > void main() > { > } > > class ExampleC > { >int x; >this (int x) @safe >{ > this.x = x; >} > >override

Re: Distinguish between a null array and an empty array

2020-05-24 Thread bauss via Digitalmars-d-learn
On Sunday, 24 May 2020 at 12:12:31 UTC, bauss wrote: Is there a way to do that? Since the following are both true: int[] a = null; int[] b = []; assert(a is null); assert(!a.length); assert(b is null); assert(!b.length); What I would like is to tell that b is an empty array and a is a null

Distinguish between a null array and an empty array

2020-05-24 Thread bauss via Digitalmars-d-learn
Is there a way to do that? Since the following are both true: int[] a = null; int[] b = []; assert(a is null); assert(!a.length); assert(b is null); assert(!b.length); What I would like is to tell that b is an empty array and a is a null array.

Re: How to flatten N-dimensional array?

2020-05-24 Thread Pavel Shkadzko via Digitalmars-d-learn
On Sunday, 24 May 2020 at 11:21:00 UTC, 9il wrote: On Saturday, 23 May 2020 at 18:15:32 UTC, Pavel Shkadzko wrote: [...] If the common nd-array isn't jugged (a parallelotop), you can use fuse function. -- /+dub.sdl: dependency "mir-algorithm" version="~>3.8.12" +/ import std.stdio:

Re: How to flatten N-dimensional array?

2020-05-24 Thread 9il via Digitalmars-d-learn
On Saturday, 23 May 2020 at 18:15:32 UTC, Pavel Shkadzko wrote: I have tried to implement a simple flatten function for multidimensional arrays with recursive templates but got stuck. Then I googled a little and stumped into complex https://rosettacode.org/wiki/Flatten_a_list#D implementation

Re: opEquals @safe is ignored

2020-05-24 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 24 May 2020 at 08:57:28 UTC, Luis wrote: dmd ignores @trusted or @safe on opEquals, throwing this error : onlineapp.d(27): Error: @safe function onlineapp.__unittest_L24_C7 cannot call @system function object.opEquals An override @system or @trusted function can't be @safe, or I

Re: How to flatten N-dimensional array?

2020-05-24 Thread Pavel Shkadzko via Digitalmars-d-learn
On Saturday, 23 May 2020 at 19:59:30 UTC, Ali Çehreli wrote: On 5/23/20 11:15 AM, Pavel Shkadzko wrote:> I have tried to implement a simple flatten function for multidimensional [...] Thank you, I was lacking practical examples for templates with "if" constructs, ehh.

opEquals @safe is ignored

2020-05-24 Thread Luis via Digitalmars-d-learn
Lets take this example code (https://run.dlang.io/is/Vkpx9j) : ´´´D import std; void main() { } class ExampleC { int x; this (int x) @safe { this.x = x; } override bool opEquals(Object o) const @trusted { if (ExampleC rhs = cast(ExampleC)o) { return this.x == rhs.x;

Using Vibe.d for not HTTP

2020-05-24 Thread Russel Winder via Digitalmars-d-learn
Hi, Clearly Vibe.d is mostly for people doing HTTP and HTTPS stuff. Yet it claims to be able to support TCP and UDP working with other protocols. However, all the serious examples are HTTP/HTTPS related. All the TCP and UDP examples are basically trivial and thus useless to me for learning. I am

Re: Learning Vibe.d

2020-05-24 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2020-05-23 at 20:52 +, Steven Schveighoffer via Digitalmars-d- learn wrote: […] > > It’s a recent problem with vibe-core. I’ve had to switch back to > version 1.8.1. > > https://github.com/vibe-d/vibe-core/issues/205 Really good to know this is a genuine problem and not just me

Re: Asserting that a base constructor is always called

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 24, 2020 12:38:46 AM MDT Tim via Digitalmars-d-learn wrote: > Oh right. I mean it makes sense but I got confused when super() > is valid syntax. Why would you need to call the super constructor > when it's called automatically? 1. If you wanted to run any code before calling the

Re: Asserting that a base constructor is always called

2020-05-24 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 24 May 2020 at 06:38:46 UTC, Tim wrote: Oh right. I mean it makes sense but I got confused when super() is valid syntax. Why would you need to call the super constructor when it's called automatically? A base class with a constructor that has no args will automatically get called

Re: Asserting that a base constructor is always called

2020-05-24 Thread Tim via Digitalmars-d-learn
On Sunday, 24 May 2020 at 00:51:17 UTC, Jonathan M Davis wrote: On Saturday, May 23, 2020 4:43:04 PM MDT Tim via Digitalmars-d-learn wrote: It is but I want to make sure for other cases in the future where I create a new class that inherits from GameObject. This was I can avoid future bugs by