How to pass noncopyable variadic arguments with ref?
tchaloupka
chalucha at gmail.com
Thu Oct 20 14:03:10 UTC 2022
Hi,
I've found strange behavior where:
```D
import std.stdio;
struct Foo
{
@disable this(this);
int x;
}
void test(Foo[] foos...)
{
foreach (ref f; foos) {
writeln(&f, ": ", f.x);
f.x = 0;
}
}
void main()
{
Foo f1 = Foo(1);
Foo f2 = Foo(2);
writeln("f1: ", &f1);
writeln("f2: ", &f2);
test(f1, f2);
writeln("f1: ", f1.x);
writeln("f2: ", f2.x);
}
```
Compiles fine (no error on passing noncopyable arguments to the
function), but there are other objects passed to the function as
they aren't cleared out in the caller scope.
Shouldn't it at least protest that objects can't be passed to the
function as they aren't copyable?
More information about the Digitalmars-d-learn
mailing list