Re: Constructing a class in-place

2018-08-02 Thread Kagamin via Digitalmars-d
On Thursday, 26 July 2018 at 12:45:52 UTC, Johan Engelen wrote: Thanks for pointing to D's placement new. This is bad news for my devirtualization work; before, I thought D is in a better situation than C++, but now it seems we may be worse off. Just say that devirtualization is incompatible w

Re: Constructing a class in-place

2018-08-01 Thread Steven Schveighoffer via Digitalmars-d
On 7/26/18 8:45 AM, Johan Engelen wrote: On Wednesday, 25 July 2018 at 08:11:59 UTC, rikki cattermole wrote: Standard solution[0]. [0] https://dlang.org/phobos/std_conv.html#.emplace.4 Thanks for pointing to D's placement new. This is bad news for my devirtualization work; before, I thought

Re: Constructing a class in-place

2018-07-28 Thread Johan Engelen via Digitalmars-d
On Thursday, 26 July 2018 at 12:53:44 UTC, rikki cattermole wrote: On 27/07/2018 12:45 AM, Johan Engelen wrote: In D, we don't have placement new, great! And now, I learn that the _standard library_ _does_ have something that looks like placement new, but without extra guarantees of the spec

Re: Constructing a class in-place

2018-07-28 Thread Johan Engelen via Digitalmars-d
On Thursday, 26 July 2018 at 21:22:45 UTC, Petar Kirov [ZombineDev] wrote: Please excuse if my question is too naive, but how does this change anything? The main insight is to reason about things in terms of language semantics, not in terms of actual memory addresses and instructions as pro

Re: Constructing a class in-place

2018-07-26 Thread Petar via Digitalmars-d
On Thursday, 26 July 2018 at 21:22:45 UTC, Petar Kirov [ZombineDev] wrote: [..] D on the other hand is (or at least I'm hopeful that it is) moving away giving magical powers to its runtime or standard library and is its embracing the spirit of bare bones systems programming where the programm

Re: Constructing a class in-place

2018-07-26 Thread Petar via Digitalmars-d
On Thursday, 26 July 2018 at 12:45:52 UTC, Johan Engelen wrote: On Wednesday, 25 July 2018 at 08:11:59 UTC, rikki cattermole wrote: Standard solution[0]. [0] https://dlang.org/phobos/std_conv.html#.emplace.4 Thanks for pointing to D's placement new. This is bad news for my devirtualization

Re: Constructing a class in-place

2018-07-26 Thread rikki cattermole via Digitalmars-d
On 27/07/2018 12:45 AM, Johan Engelen wrote: On Wednesday, 25 July 2018 at 08:11:59 UTC, rikki cattermole wrote: Standard solution[0]. [0] https://dlang.org/phobos/std_conv.html#.emplace.4 Thanks for pointing to D's placement new. This is bad news for my devirtualization work; before, I tho

Re: Constructing a class in-place

2018-07-26 Thread Johan Engelen via Digitalmars-d
On Wednesday, 25 July 2018 at 08:11:59 UTC, rikki cattermole wrote: Standard solution[0]. [0] https://dlang.org/phobos/std_conv.html#.emplace.4 Thanks for pointing to D's placement new. This is bad news for my devirtualization work; before, I thought D is in a better situation than C++, but

Re: Constructing a class in-place

2018-07-25 Thread rikki cattermole via Digitalmars-d
On 25/07/2018 8:05 PM, Shachar Shemesh wrote: Forget the "why" for the moment. T construct(T, ARGS...)(ARGS args) if( is(T==class) ) {    auto buffer = new ubyte[__traits(classInstanceSize, T)];    T cls = cast(T)buffer.ptr; Allocates the storage space of the fields (both public and private)

Constructing a class in-place

2018-07-25 Thread Shachar Shemesh via Digitalmars-d
Forget the "why" for the moment. T construct(T, ARGS...)(ARGS args) if( is(T==class) ) { auto buffer = new ubyte[__traits(classInstanceSize, T)]; T cls = cast(T)buffer.ptr; // Is this really the best way to do this? buffer[] = cast(ubyte[])typeid(T).initializer()[]; cls.__ctor(arg