November 29, 2021

On Monday, 29 November 2021 at 08:35:06 UTC, Stanislav Blinov wrote:

>

(..)

Oh i see.., thanks for being patient with me and providing me links where i can read more about it! sorry for derailing the post!

December 13, 2021

On Saturday, 27 November 2021 at 21:56:05 UTC, Stanislav Blinov wrote:

>
T stuff = T(args); // or new T(args);

but this?..

T* ptr = allocateForT();
// now what?.. Can't just do *ptr = T(args) - that's an assignment, not initialization!
// is T a struct? A union? A class? An int?.. Is it even a constructor call?..

What about taking inspiration from C++'s

https://en.cppreference.com/w/cpp/language/new#Placement_new

? Allocators could be supported by either

  • passing the allocator as to new() as an the first normal or template parameter or
  • have new be defineable as a member function of an allocator (or any struct or class)

?

December 19, 2021

On Saturday, 27 November 2021 at 21:56:05 UTC, Stanislav Blinov wrote:

>

D lacks syntax for initializing the uninitialized. We can do this:

[...]

Think this can help with that void initialization problem? We can have a node attribute isInitialized in the frontend, depending on which we can decide whether to call the destructor or not at the end of the scope?

January 04, 2022

On Saturday, 27 November 2021 at 21:56:05 UTC, Stanislav Blinov wrote:

>

...

Nice idea, placement new really missing from D.

I have reverse problem with emplace then you.
emplaceRef wrongly infers @safe attribute for non ctfe code if assignment is @system because of this:

//emplaceRef:
if (__ctfe)
    ///...
    chunk = forward!(args[0]);
    ///...
}

Example:

struct Foo{

    this(scope ref const typeof(this) rhs)@safe{}

    void opAssign(scope ref const typeof(this) rhs)@system{}
}


void main()@safe{
    import core.lifetime : emplace;

    Foo foo;
    {
        const Foo* ptr;
        emplace(ptr, foo);	//OK __ctfe path doesn't exists
    }
    {
        Foo* ptr;
        emplace(ptr, foo);	//ERROR __ctfe path exists and call @system opAssign
    }
}

Error: @safe function D main cannot call @system function core.lifetime.emplace!(Foo, Foo).emplace

D has one good thing, you can create custom emplace which run your own code between emplaceInitialize and ctor. You can initialize your own vptr before ctor.

1 2
Next ›   Last »