Re: DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Thursday, 20 June 2019 at 00:30:35 UTC, Jonathan M Davis wrote: Ultimately, if you want a function to accept both rvalues and lvalues as efficiently as posible, just templatize it and use auto ref. I'm aware of auto ref, and I've used it to solve this same problem when I had a template,

Re: create and initialise array

2019-06-19 Thread matheus via Digitalmars-d-learn
On Thursday, 20 June 2019 at 01:06:09 UTC, Alex wrote: Is there a way of creating and initialising a dynamic array ? for example I am doing this: auto arr = new float[]; arr[] = 0.0f; Profiling indicates that the compiler (gdc) is spending significant time memsetting the whole array to

create and initialise array

2019-06-19 Thread Alex via Digitalmars-d-learn
Is there a way of creating and initialising a dynamic array ? for example I am doing this: auto arr = new float[]; arr[] = 0.0f; Profiling indicates that the compiler (gdc) is spending significant time memsetting the whole array to something (nan ?) before I immediately memset it to 0.0f.

Re: DIP 1016 and const ref parameters

2019-06-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 19, 2019 4:45:04 PM MDT XavierAP via Digitalmars-d-learn wrote: > On Wednesday, 19 June 2019 at 21:06:48 UTC, XavierAP wrote: > > Now with an rvalue returned from get, interesting, no copy. > > Still, I wonder what really happened. Again, moving between > > stacks would still

Re: DIP 1016 and const ref parameters

2019-06-19 Thread Les De Ridder via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 20:18:58 UTC, Max Haughton wrote: On Wednesday, 19 June 2019 at 19:25:59 UTC, Jonathan M Davis wrote: On Wednesday, June 19, 2019 12:28:12 PM MDT XavierAP via Digitalmars-d-learn wrote: [...] The DIPs are here: https://github.com/dlang/DIPs [...] DIP1014 has

Re: The problem with the conversion.

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 17:28:38 UTC, XavierAP wrote: Also, the return type of SDL_LoadBMP is a pointer, SDL_Surface* not just SDL_Surface. Or just use auto of course if you prefer: void load (string path) { import std.string : toStringz; auto ab = SDL_LoadBMP

Re: DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 21:06:48 UTC, XavierAP wrote: Now with an rvalue returned from get, interesting, no copy. Still, I wonder what really happened. Again, moving between stacks would still be work. And a different optimization can explain this non copy, for example inlining. My

Re: Is it possible to escape a reserved keyword in Import/module?

2019-06-19 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 21:21:53 UTC, XavierAP wrote: On Wednesday, 19 June 2019 at 18:56:57 UTC, BoQsc wrote: I would like to make sure that my modules do not interfere with d lang. Is there any way to escape reserved words? The only reason C# allows this is for interop or code

Re: Is it possible to escape a reserved keyword in Import/module?

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 18:56:57 UTC, BoQsc wrote: I would like to make sure that my modules do not interfere with d lang. Is there any way to escape reserved words? The only reason C# allows this is for interop or code generation for other languages that use the same keyword. For

Re: Is it possible to escape a reserved keyword in Import/module?

2019-06-19 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 19:07:30 UTC, Jonathan M Davis wrote: On Wednesday, June 19, 2019 12:56:57 PM MDT BoQsc via Digitalmars-d-learn wrote: I would like to make sure that my modules do not interfere with d lang. Is there any way to escape reserved words?

Re: DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
Hmmm I know about move semantics, and C++11 etc. I just don't know how related all that is to my original question. :) On Wednesday, 19 June 2019 at 19:25:59 UTC, Jonathan M Davis wrote: though if I understand correctly with RVO, it may just place the return value outside of the function in

Re: DIP 1016 and const ref parameters

2019-06-19 Thread Max Haughton via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 19:25:59 UTC, Jonathan M Davis wrote: On Wednesday, June 19, 2019 12:28:12 PM MDT XavierAP via Digitalmars-d-learn wrote: [...] The DIPs are here: https://github.com/dlang/DIPs [...] DIP1014 has not been implemented in DMD or druntime yet, AFAIK

Re: DIP 1016 and const ref parameters

2019-06-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 19, 2019 12:28:12 PM MDT XavierAP via Digitalmars-d-learn wrote: > On Wednesday, 19 June 2019 at 12:55:09 UTC, Jonathan M Davis > > wrote: > > Even in C++, using const ref is not as good a practice as it > > once was, because they added move constructors, finally making > >

Re: Is it possible to escape a reserved keyword in Import/module?

2019-06-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 19, 2019 12:56:57 PM MDT BoQsc via Digitalmars-d-learn wrote: > I would like to make sure that my modules do not interfere with d > lang. Is there any way to escape reserved words? > https://dlang.org/spec/lex.html#keywords > > > import alias; > >

Is it possible to escape a reserved keyword in Import/module?

2019-06-19 Thread BoQsc via Digitalmars-d-learn
I would like to make sure that my modules do not interfere with d lang. Is there any way to escape reserved words? https://dlang.org/spec/lex.html#keywords import alias; C:\Users\Juozas\Desktop\om.d(2): Error: identifier expected following import C:\Users\Juozas\Desktop\om.d(2): Error: ;

Re: DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 12:55:09 UTC, Jonathan M Davis wrote: Even in C++, using const ref is not as good a practice as it once was, because they added move constructors, finally making object moveable. The result is that in many cases, it's actually more efficient to just copy values

Re: What is the difference between extern(C++) extern(D)

2019-06-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 19, 2019 11:12:14 AM MDT lili via Digitalmars-d-learn wrote: > Hi Guys; > In the dmd source code, has lot of extern (C++), Why need this > and what is difference between extern(C++) extern(D), Thanks your > answer. extern(C++) is for making the name mangling match C++,

Re: Strange behavior of opEquals for structs

2019-06-19 Thread harfel via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 17:15:31 UTC, Ali Çehreli wrote: On 06/19/2019 08:28 AM, harfel wrote: You need to define toHash() member function as well: https://dlang.org/spec/hash-map.html#using_struct_as_key Ali Thanks Ali, This fixed my problem, of course. Amazing that such a

Re: The problem with the conversion.

2019-06-19 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 14:58:44 UTC, drug wrote: 19.06.2019 17:52, Den_d_y пишет: void load (const (char *) path) {     SDL_Surface ab = SDL_LoadBMP (path);     a = SDL_CreateTextureFromSurface (ab);     SDL_FreeSurface (ab); } try the following: ``` void load (string path) {

Re: Strange behavior of opEquals for structs

2019-06-19 Thread Ali Çehreli via Digitalmars-d-learn
On 06/19/2019 08:28 AM, harfel wrote: Everything works nicely if I compare the structs directly. Yet when they are used as keys in an associative array, the code throws an exception that I do not understand. You need to define toHash() member function as well:

What is the difference between extern(C++) extern(D)

2019-06-19 Thread lili via Digitalmars-d-learn
Hi Guys; In the dmd source code, has lot of extern (C++), Why need this and what is difference between extern(C++) extern(D), Thanks your answer.

Re: Where can find fix length array memory layout document

2019-06-19 Thread lili via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 12:53:05 UTC, Cym13 wrote: Did you import it properly? ``` void main() { import core.stdcpp.array; auto a = array!(int, 4)(); } ``` compiles and runs without issue for me. You'll have to show your code if you want people to help you

Strange behavior of opEquals for structs

2019-06-19 Thread harfel via Digitalmars-d-learn
I am trying to overload opEquals for a struct. The struct will hold class objects that define their own opEquals so the default bitwise comparison is not good for me. Everything works nicely if I compare the structs directly. Yet when they are used as keys in an associative array, the code

Re: The problem with the conversion.

2019-06-19 Thread drug via Digitalmars-d-learn
19.06.2019 17:52, Den_d_y пишет: void load (const (char *) path) {     SDL_Surface ab = SDL_LoadBMP (path);     a = SDL_CreateTextureFromSurface (ab);     SDL_FreeSurface (ab); } try the following: ``` void load (string path) { import std.string : toStringz; SDL_Surface ab =

The problem with the conversion.

2019-06-19 Thread Den_d_y via Digitalmars-d-learn
Hello, users of this programming language! I have a question. I use in my application Derelict SDL 2 version 2.1.4. And when I try to specify the path to the image: void load (const (char *) path) { SDL_Surface ab = SDL_LoadBMP (path); a = SDL_CreateTextureFromSurface (ab);

Re: DIP 1016 and const ref parameters

2019-06-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 19, 2019 6:33:44 AM MDT XavierAP via Digitalmars-d-learn wrote: > I often use a pattern of having const ref struct parameters (as > in C++) but this doesn't work in the case of rvalues. The > workaround of defining an overload that calls its own name is > terrible. I understand

Re: Where can find fix length array memory layout document

2019-06-19 Thread Cym13 via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 05:27:12 UTC, lili wrote: On Tuesday, 18 June 2019 at 17:29:49 UTC, Cym13 wrote: On Tuesday, 18 June 2019 at 17:25:42 UTC, Cym13 wrote: On Tuesday, 18 June 2019 at 13:05:03 UTC, lili wrote: On Tuesday, 18 June 2019 at 12:39:45 UTC, Dennis wrote: [...] Thanks a

DIP 1016 and const ref parameters

2019-06-19 Thread XavierAP via Digitalmars-d-learn
I often use a pattern of having const ref struct parameters (as in C++) but this doesn't work in the case of rvalues. The workaround of defining an overload that calls its own name is terrible. I understand there was a DIP 1016 by Manu asking for this case to work. As far as I can tell, this

Re: Blog Post #0045 - Split a Window into Panes

2019-06-19 Thread Ron Tarrant via Digitalmars-d-learn
On Tuesday, 18 June 2019 at 13:19:48 UTC, Ron Tarrant wrote: And just a quick tip of the hat Forgot to thank Russell Winder for suggesting Previous/Next buttons which have also been implemented on all pages. Should make navigation easier for those multi-part posts.

Re: is there any micro-service library in D?

2019-06-19 Thread Marco de Wild via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 08:29:15 UTC, dangbinghoo wrote: hi there, Does anyone know the micro-service oriented design library or framework in D? thanks! binghoo dang What do you need from such a library? Some suggestions: For networking, there is vibe.d[0] which provides both

Re: Component based programming in D

2019-06-19 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 18 June 2019 at 09:17:09 UTC, Bart wrote: I'm new to component based programming. I've read it is an alternative to oop for speed. Component based modelling is part of the OO-modelling toolbox. Also, it isn't new, e.g. database-oriented modelling techniques often use the same

Re: Hyperterminal serial port

2019-06-19 Thread UlanReed via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 06:52:33 UTC, IanFisher wrote: Hi, I am wanting to establish a virtual serial port connection between an 89c51 being emulated in Proteus and Hyper Terminal running in Windows. How do I go about doing this? Thanks in advance Hello. Look at the reply above

is there any micro-service library in D?

2019-06-19 Thread dangbinghoo via Digitalmars-d-learn
hi there, Does anyone know the micro-service oriented design library or framework in D? thanks! binghoo dang

Hyperterminal serial port

2019-06-19 Thread IanFisher via Digitalmars-d-learn
Hi, I am wanting to establish a virtual serial port connection between an 89c51 being emulated in Proteus and Hyper Terminal running in Windows. How do I go about doing this? Thanks in advance

Re: Why after writeln the binaryHeap become empty?

2019-06-19 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 19 June 2019 at 06:00:28 UTC, Jonathan M Davis wrote: On Tuesday, June 18, 2019 10:27:46 PM MDT lili via Do you known reason for why Dlang Range are consumed by iterating over them. I this design is strange. If you want an overview of ranges, you can watch this:

Re: Why after writeln the binaryHeap become empty?

2019-06-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 18, 2019 10:27:46 PM MDT lili via Digitalmars-d-learn wrote: > On Tuesday, 18 June 2019 at 17:25:51 UTC, Johannes Loher wrote: > > The result of heapify is a BinaryHeap, which is a range. writeln > > basically prints ranges by iterating over them and printing > > each element > >