Re: Any way to automatically convert structs on return?

2024-08-01 Thread Emma via Digitalmars-d-learn
Thanks everyone for the replies! I just thought it was weird that implicit construction is seemingly supported when directly initialising a struct but not in any other case. I guess it's because it's clearly less ambiguous. On Thursday, 1 August 2024 at 13:07:09 UTC, Lance Bachmeier wrote: F

Any way to automatically convert structs on return?

2024-08-01 Thread Emma via Digitalmars-d-learn
This code works: ```d struct None {} struct Option(T) { bool hasSome; T value; this(None) {} this(T v) { hasSome = true; value = v; } } Option!int a = 123;// automatically constructs an Option!int from a bare int Option!int b = None(); // same as abov

Member function passed through template alias only requiring `this` in certain conditions?

2018-07-19 Thread Emma via Digitalmars-d-learn
Hello, I’ve got this piece of code: --- import std.stdio; void test(alias fn1, alias fn2)() { fn1(); fn2(); } struct Foo { void foo() { test!(bar, baz); } void bar() {} void baz() {} } --- If I try to compile it, dmd complains, which I guess makes