Move Constructors - Converting Lvalues to Rvalues

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Tue Oct 1 16:43:09 UTC 2024


Now to get annoying again:

What is the difference between move assignment @move + reference 
counting, and move constructors?

```d
void caller() {
	T thing = ...; // rc: 1
	call1(thing);
	call2(thing);
	// ?reachable thing
	thing.opRCSub(); // elided due to having been moved
	thing.__dtor; // elided due to reachable type state
}

void call1(T thing) {
	thing.opRCAdd(); // elided due to pair
	thing.opRCSub(); // elided due to pair
	thing.__dtor;
}

void call2(@move T thing) {
	thing.opRCAdd(); // elided due to @move
	thing.opRCSub();
	thing.__dtor;
}
```



More information about the Digitalmars-d mailing list