rval->ref const(T), implicit conversions
tsbockman via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jan 18 10:08:31 PST 2016
On Monday, 18 January 2016 at 15:36:09 UTC, Manu wrote:
> One more time...
>
> Assuming:
> void func(const CustomString &s1, const CustomString &s2);
> void func(ref const(CustomString) s1, ref const(CustomString)
> s2);
>
> C++:
> func("hello", "world");
>
> D:
> auto dumb_name = CustomString("hello");
> auto another_dumb_name = CustomString("world");
> func(dumb_name, another_dumb_name);
Actually, I was way overthinking things. Does *this* do what you
want?
import std.stdio;
struct CustomString {
this(string data) {
this.data = data;
}
string data;
alias data this;
}
void func(ref CustomString s1, ref CustomString s2) {
writeln(s1);
writeln(s2);
s2 = "universe!";
}
pragma(inline, true)
void arFunc(T, V)(auto ref T s1, auto ref V s2) {
func(s1, s2);
}
void main() {
CustomString b = CustomString("world!");
arFunc(CustomString("Hello"), b);
writeln("Hello");
writeln(b);
}
Again, I can probably automate generation of the wrapper easily
enough.
More information about the Digitalmars-d
mailing list