On Sunday, 12 December 2021 at 18:32:28 UTC, Imperatorn wrote:
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?

```d
struct Foo(T){
    this(Rhs, this This)(scope Rhs rhs){
    }

    this(ref scope typeof(this) rhs){
    }
}


struct Bar{
        Foo!int foo;
}

void main(){
}
```

error: Segmentation fault (core dumped)

What are you trying to accomplish?

Something like this:

```d
import std.traits : CopyConstness;

struct UniquePtr(T){
    alias Type = T;

    this(Rhs, this This)(scope Rhs rhs)
if(is(CopyConstness!(Rhs, Rhs.Type*) : CopyConstness!(This, This.Type*))){
        //...
    }

    //one of copy ctors:
    this(ref scope typeof(this) rhs){
        //...
    }

    static UniquePtr make(Args...)(Args args){
        return UniquePtr.init;
    }
}


void main(){
    const UniquePtr!(int) cui = UniquePtr!(const int).make(1);
const UniquePtr!(const int) cuci = UniquePtr!(const int).make(1);
    UniquePtr!(const int) uci = UniquePtr!(int).make(1);
    UniquePtr!(int) ui = UniquePtr!(int).make(1);

const UniquePtr!(int) xcui = UniquePtr!(immutable int).make(1); const UniquePtr!(const int) xcuci = UniquePtr!(immutable int).make(1);

}
```

This work but UniquePtr canno't be inside struct because Segmentation fault.

Reply via email to