Re: structs inheriting from and implementing interfaces

2018-01-01 Thread Laeeth Isharc via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:59:21 UTC, rjframe wrote: On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote: On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: The problem is that interfaces are a runtime thing (e.g. you can cast a class to an interface) structs

Re: structs inheriting from and implementing interfaces

2018-01-01 Thread Meta via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: In C#, structs can inherit from and implement interfaces. using System; interface IPrint { void Print(); } struct MyStruct : IPrint { public void Print() { Console.WriteLine(ToString()); } } public

Re: Help optimizing code?

2018-01-01 Thread Uknown via Digitalmars-d-learn
On Monday, 1 January 2018 at 15:09:53 UTC, Lily wrote: I started learning D a few days ago, coming from some very basic C++ knowledge, and I'd like some help getting a program to run faster. The code is here: https://github.com/IndigoLily/D-mandelbrot/blob/master/mandelbrot.d Right now it

Re: Help optimizing code?

2018-01-01 Thread Uknown via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 07:17:23 UTC, Uknown wrote: [snip] 0. Use LDC. It is significantly faster. 1. Utilize the fact that the Mandelbrot set is symmetric about the X axis.You can half the time taken. 2. Use std.parallelism for using multiple cores on the CPU 3. Use @fastmath of LDC 4.

Help optimizing code?

2018-01-01 Thread Lily via Digitalmars-d-learn
I started learning D a few days ago, coming from some very basic C++ knowledge, and I'd like some help getting a program to run faster. The code is here: https://github.com/IndigoLily/D-mandelbrot/blob/master/mandelbrot.d Right now it runs slower than my JavaScript Mandelbrot renderer on the

Re: Help optimizing code?

2018-01-01 Thread user1234 via Digitalmars-d-learn
On Monday, 1 January 2018 at 15:09:53 UTC, Lily wrote: I started learning D a few days ago, coming from some very basic C++ knowledge, and I'd like some help getting a program to run faster. The code is here: https://github.com/IndigoLily/D-mandelbrot/blob/master/mandelbrot.d Right now it

Re: Help optimizing code?

2018-01-01 Thread user1234 via Digitalmars-d-learn
On Monday, 1 January 2018 at 15:23:19 UTC, Adam D. Ruppe wrote: On Monday, 1 January 2018 at 15:09:53 UTC, Lily wrote: I started learning D a few days ago, coming from some very basic C++ knowledge, and I'd like some help getting a program to run faster. So a few easy things you can do: 1)

Re: std.file and non-English filename in Windows

2018-01-01 Thread tipdbmp via Digitalmars-d-learn
I think you have to decode your input to UTF-8. stdin .byLineCopy(No.keepTerminator) .each!((string file_name_raw) { // change Latin1String to the code page of your console; // use the 'chcp' command to see the current code page of your console // import std.encoding; auto

Re: How do you safely deal with range.front?

2018-01-01 Thread aliak via Digitalmars-d-learn
On Monday, 1 January 2018 at 04:18:29 UTC, Ali Çehreli wrote: If you're fine with specifying the function as a template argument, the following works. (As seen with 's => s.foo()' below, you have to use a lambda for member functions anyway.) Ali Nice! Thanks :) And I think your usage for

Re: How do you safely deal with range.front?

2018-01-01 Thread aliak via Digitalmars-d-learn
On Monday, 1 January 2018 at 02:18:36 UTC, Jonathan M Davis wrote: Except that the reason for arrays throwing RangeErrors when you try and index them out-of-bounds is to avoid memory safety issues, which is not necessarily the case at all when you're talking about ranges. Having ranges in

Re: static if and early exit from function doesn't seem to work?

2018-01-01 Thread aliak via Digitalmars-d-learn
On Sunday, 31 December 2017 at 13:47:32 UTC, Adam D. Ruppe wrote: On Sunday, 31 December 2017 at 13:32:03 UTC, aliak wrote: So it seems it tries to compile the statements below the check on V.length even though it's guaranteed to be true and there's a return statement inside the if. Yeah,

Re: std.file and non-English filename in Windows

2018-01-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 01, 2018 10:47:51 Patrick Schluter via Digitalmars-d- learn wrote: > On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote: > > In Windows, exists, rename, copy will report file not exists > > when you input non-English filename, such as Chinese 中文.txt > > It's unclear what

Re: std.file and non-English filename in Windows

2018-01-01 Thread John Chapman via Digitalmars-d-learn
On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote: In Windows, exists, rename, copy will report file not exists when you input non-English filename, such as Chinese 中文.txt Works for me. I created a file with the name "中文.txt" and std.file.exists returned true. Is your D source file

Re: Finding unsafe line of code

2018-01-01 Thread Vino via Digitalmars-d-learn
On Friday, 29 December 2017 at 10:33:16 UTC, Johan Engelen wrote: On Friday, 29 December 2017 at 10:23:24 UTC, codephantom wrote: On Friday, 29 December 2017 at 09:38:50 UTC, Vino wrote: Let me re-frame the question with an example, as the Dsafe the below line of code is considered as

Re: Help optimizing code?

2018-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 1 January 2018 at 15:29:28 UTC, user1234 wrote: dmd mandelbrot.d -O -release -inline -boundscheck=off -O and -inline are OK, but -release and -boundscheck are harmful and shouldn't be used. Yeah, you can squeeze a bit of speed out of them, but there's another way to do it -

Re: Help optimizing code?

2018-01-01 Thread Muld via Digitalmars-d-learn
On Monday, 1 January 2018 at 15:54:33 UTC, Adam D. Ruppe wrote: On Monday, 1 January 2018 at 15:29:28 UTC, user1234 wrote: dmd mandelbrot.d -O -release -inline -boundscheck=off -O and -inline are OK, but -release and -boundscheck are harmful and shouldn't be used. Yeah, you can squeeze a

Re: std.file and non-English filename in Windows

2018-01-01 Thread Domain via Digitalmars-d-learn
On Monday, 1 January 2018 at 12:33:27 UTC, John Chapman wrote: On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote: In Windows, exists, rename, copy will report file not exists when you input non-English filename, such as Chinese 中文.txt Works for me. I created a file with the name

Re: structs inheriting from and implementing interfaces

2018-01-01 Thread rjframe via Digitalmars-d-learn
On Tue, 02 Jan 2018 00:54:13 +, Laeeth Isharc wrote: > On Friday, 29 December 2017 at 12:59:21 UTC, rjframe wrote: >> On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote: >> >> I've actually thought about doing this to get rid of a bunch of if >> qualifiers in my function declarations.

Re: std.file and non-English filename in Windows

2018-01-01 Thread Patrick Schluter via Digitalmars-d-learn
On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote: In Windows, exists, rename, copy will report file not exists when you input non-English filename, such as Chinese 中文.txt It's unclear what your problem is but here a wild guess. Windows API's for Unicode use UTF-16 as far as I know.

Re: Help optimizing code?

2018-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 1 January 2018 at 15:09:53 UTC, Lily wrote: I started learning D a few days ago, coming from some very basic C++ knowledge, and I'd like some help getting a program to run faster. So a few easy things you can do: 1) use `float` instead of `real`. real sucks, it is really slow and

Re: Help optimizing code?

2018-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 1 January 2018 at 16:13:37 UTC, Muld wrote: If you use .ptr then you get zero detection, even in debug builds. It is limited to the one expression where you wrote it, instead of on the ENTIRE program like the build switches do. It is a lot easier to check correctness in an

Re: Does UDA not work for enums?

2018-01-01 Thread Seb via Digitalmars-d-learn
On Monday, 1 January 2018 at 17:15:24 UTC, Marc wrote: I got compilers errors from this: enum E { @("foo") A, @("baa") B } I got: Error: basic type expected, not @ Error: no identifier for declarator _error_ Error: type only allowed if anonymous enum and no

Does UDA not work for enums?

2018-01-01 Thread Marc via Digitalmars-d-learn
I got compilers errors from this: enum E { @("foo") A, @("baa") B } I got: Error: basic type expected, not @ Error: no identifier for declarator _error_ Error: type only allowed if anonymous enum and no enum type Error: if type, there must be an initializer

Re: Slices and Dynamic Arrays

2018-01-01 Thread Seb via Digitalmars-d-learn
On Monday, 1 January 2018 at 02:10:14 UTC, Jonathan M Davis wrote: On Sunday, December 31, 2017 14:49:40 Tony via Digitalmars-d-learn wrote: On Sunday, 31 December 2017 at 14:24:40 UTC, Jonathan M Davis wrote: > [...] The DLang Tour also uses the term slice to refer to T[]. "The type of arr

Re: std.file and non-English filename in Windows

2018-01-01 Thread Domain via Digitalmars-d-learn
On Monday, 1 January 2018 at 16:13:06 UTC, Domain wrote: On Monday, 1 January 2018 at 12:33:27 UTC, John Chapman wrote: On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote: In Windows, exists, rename, copy will report file not exists when you input non-English filename, such as Chinese

Re: Help optimizing code?

2018-01-01 Thread Muld via Digitalmars-d-learn
On Monday, 1 January 2018 at 16:47:40 UTC, Adam D. Ruppe wrote: On Monday, 1 January 2018 at 16:13:37 UTC, Muld wrote: If you use .ptr then you get zero detection, even in debug builds. It is limited to the one expression where you wrote it, instead of on the ENTIRE program like the build