On Friday, 13 August 2021 at 21:34:29 UTC, Steven Schveighoffer
wrote:
But for constructors it's not the same. Essentially because
constructors have different rules for what they can do with
their inputs (the inout `this` parameter can be assigned to for
the member's first assignment).
What I
On 8/13/21 4:58 PM, Paul Backus wrote:
On Friday, 13 August 2021 at 15:26:15 UTC, Steven Schveighoffer wrote:
The issue is that you can't convert const (or immutable or mutable) to
inout implicitly, and the member variable is inout inside an inout
constructor. Therefore, there's no viable copy
On Friday, 13 August 2021 at 15:26:15 UTC, Steven Schveighoffer
wrote:
The issue is that you can't convert const (or immutable or
mutable) to inout implicitly, and the member variable is inout
inside an inout constructor. Therefore, there's no viable copy
constructor to call for the member, and
On 8/12/21 12:12 PM, Paul Backus wrote:
The reason for this is a bit subtle. Normally, `inout` can convert to
`const`, so you might expect that the `const` copy constructor could be
used to construct a copy of an `inout` object. However, copy
constructors take their arguments by `ref`, and impl
On 8/12/21 4:32 AM, Paul Backus wrote:
> Qualifying the ctor as `inout` works fine
I can see how a DConf Online presention is shaping up in your head. ;)
http://dconf.org/2021/online/index.html
We need a collective understanding of effective use of such fundamental
concepts.
Ali
On Thursday, 12 August 2021 at 16:12:39 UTC, Paul Backus wrote:
On Thursday, 12 August 2021 at 15:39:40 UTC, Learner wrote:
[...]
You have forgotten to add a member variable of type `A` to your
`B` struct. If you add one, you will see the following error
message:
[...]
"implicit conversi
On Thursday, 12 August 2021 at 15:39:40 UTC, Learner wrote:
It is not clear to me why the inout generated copy constructor
of the B structure is not able to copy the A structure.
struct A
{
int[] data;
this(ref return scope A rhs){ /*
body */ }
On Thursday, 12 August 2021 at 15:50:05 UTC, Tejas wrote:
On Thursday, 12 August 2021 at 15:39:40 UTC, Learner wrote:
On Thursday, 12 August 2021 at 14:57:16 UTC, Steven
Schveighoffer wrote:
[...]
It is not clear to me why the inout generated copy constructor
of the B structure is not able t
On Thursday, 12 August 2021 at 15:39:40 UTC, Learner wrote:
On Thursday, 12 August 2021 at 14:57:16 UTC, Steven
Schveighoffer wrote:
[...]
It is not clear to me why the inout generated copy constructor
of the B structure is not able to copy the A structure.
[...]
Why will copy constructor
On Thursday, 12 August 2021 at 14:57:16 UTC, Steven Schveighoffer
wrote:
On 8/12/21 10:08 AM, Learner wrote:
On Thursday, 12 August 2021 at 13:56:17 UTC, Paul Backus wrote:
On Thursday, 12 August 2021 at 12:10:49 UTC, Learner wrote:
That worked fine, but the codebase is @safe:
```d
cast from
On 8/12/21 10:08 AM, Learner wrote:
On Thursday, 12 August 2021 at 13:56:17 UTC, Paul Backus wrote:
On Thursday, 12 August 2021 at 12:10:49 UTC, Learner wrote:
That worked fine, but the codebase is @safe:
```d
cast from `int[]` to `inout(int[])` not allowed in safe code
```
So copy construct
On Thursday, 12 August 2021 at 13:56:17 UTC, Paul Backus wrote:
On Thursday, 12 August 2021 at 12:10:49 UTC, Learner wrote:
That worked fine, but the codebase is @safe:
```d
cast from `int[]` to `inout(int[])` not allowed in safe code
```
So copy constructors force me to introduce trusted met
On Thursday, 12 August 2021 at 12:10:49 UTC, Learner wrote:
That worked fine, but the codebase is @safe:
```d
cast from `int[]` to `inout(int[])` not allowed in safe code
```
So copy constructors force me to introduce trusted methods,
while that was not necessary with postblits?
A postblit
On Thursday, 12 August 2021 at 12:28:32 UTC, Learner wrote:
On Thursday, 12 August 2021 at 12:22:22 UTC, Tejas wrote:
On Thursday, 12 August 2021 at 12:19:56 UTC, Tejas wrote:
[...]
Works with ```@safe``` as well
Paul was just trying to make that other answer work, you don't
have to make co
On Thursday, 12 August 2021 at 12:22:22 UTC, Tejas wrote:
On Thursday, 12 August 2021 at 12:19:56 UTC, Tejas wrote:
[...]
Works with ```@safe``` as well
Paul was just trying to make that other answer work, you don't
have to make copy constructors ```@trusted```
Ignore this, it doesn't wor
On Thursday, 12 August 2021 at 12:22:22 UTC, Tejas wrote:
On Thursday, 12 August 2021 at 12:19:56 UTC, Tejas wrote:
[...]
Works with ```@safe``` as well
Paul was just trying to make that other answer work, you don't
have to make copy constructors ```@trusted```
Operations are needed on `ot
On Thursday, 12 August 2021 at 12:19:56 UTC, Tejas wrote:
On Thursday, 12 August 2021 at 11:54:22 UTC, Learner wrote:
[...]
Just add ```inout``` inside ```this(ref inout/*notice the
inout*/ Foo other) inout/*notice the inout*/```
Example code:
```d
struct Foo {
this(ref inout Foo ot
On Thursday, 12 August 2021 at 11:54:22 UTC, Learner wrote:
On Thursday, 12 August 2021 at 10:10:17 UTC, rikki cattermole
wrote:
On 12/08/2021 9:36 PM, Learner wrote:
It seems that there is no easy way to transition from a
postblit to a copy constructor, no?
struct Foo {
this(ref Foo
On Thursday, 12 August 2021 at 11:32:03 UTC, Paul Backus wrote:
On Thursday, 12 August 2021 at 11:19:34 UTC, drug wrote:
```D
struct A {
int[] data;
this(ref return scope inout A rhs) /* no inout here */ {
data = rhs.data.dup; }
}
```
The problem is that if you qualify the ctor itself
On Thursday, 12 August 2021 at 11:07:24 UTC, drug wrote:
12.08.2021 12:36, Learner пишет:
> It seems that there is no easy way to transition from a
postblit to a
copy constructor, no?
You just need both const and mutable copy ctors to replace
inout one:
```D
struct A {
int[] data;
12.08.2021 14:32, Paul Backus пишет:
This is not true. Qualifying the ctor as `inout` works fine:
https://run.dlang.io/is/Kpzp5M
The problem in this example is that `.dup` always returns a mutable
array, even if the array being copied is `inout`. The solution is to
cast the copy back to the
On Thursday, 12 August 2021 at 10:10:17 UTC, rikki cattermole
wrote:
On 12/08/2021 9:36 PM, Learner wrote:
It seems that there is no easy way to transition from a
postblit to a copy constructor, no?
struct Foo {
this(ref Foo other) {
foreach(i, v; other.tupleof)
On Thursday, 12 August 2021 at 11:19:34 UTC, drug wrote:
```D
struct A {
int[] data;
this(ref return scope inout A rhs) /* no inout here */ {
data = rhs.data.dup; }
}
```
The problem is that if you qualify the ctor itself then if you
pass const/immutable rhs to it then the ctor is cons
12.08.2021 14:07, drug пишет:
12.08.2021 12:36, Learner пишет:
> It seems that there is no easy way to transition from a postblit to a
copy constructor, no?
You just need both const and mutable copy ctors to replace inout one:
```D
struct A {
int[] data;
this(ref return scope A
12.08.2021 12:36, Learner пишет:
> It seems that there is no easy way to transition from a postblit to a
copy constructor, no?
You just need both const and mutable copy ctors to replace inout one:
```D
struct A {
int[] data;
this(ref return scope A rhs) { data = rhs.data.dup; }
On 12/08/2021 9:36 PM, Learner wrote:
It seems that there is no easy way to transition from a postblit to a
copy constructor, no?
struct Foo {
this(ref Foo other) {
foreach(i, v; other.tupleof)
this.tupleof[i] = v;
}
@disable th
On Thursday, 12 August 2021 at 09:14:02 UTC, Paul Backus wrote:
On Thursday, 12 August 2021 at 08:42:27 UTC, Learner wrote:
struct A {
int[] data
this(ref return scope A rhs) { data = ths.data.dup; }
}
Generating an `inout` copy constructor for `struct B`
failed, th
On Thursday, 12 August 2021 at 08:42:27 UTC, Learner wrote:
struct A {
int[] data
this(ref return scope A rhs) { data = ths.data.dup; }
}
Generating an `inout` copy constructor for `struct B`
failed, therefore instances of it are uncopyable
What is an `inout` copy
I have a structure like, used by other structures:
struct A {
int[] data;
this(this) { data = data.dup; }
}
I am trying to upgrade it to use copy constructor:
struct A {
int[] data
this(ref return scope A rhs) { data = ths.data.dup; }
}
Gener
29 matches
Mail list logo