On 2/11/22 16:41, H. S. Teoh wrote:
> How about this?
>
>
> final class Boxed(T) {
>T payload;
>alias payload this; // caveat: probably not a good idea in general
>this(T val) { payload = val; }
> }
>
> Boxed!int i = new Boxed!int(123);
> int j = i; // hooray, implicit unboxi
On Saturday, 12 February 2022 at 16:50:16 UTC, H. S. Teoh wrote:
Without alias this it would be harder to pull off, yes.
I don't see any other way that allows to unbox *implictly*.
That would require a new operator. Something like opCast but more
permissive, that works without `cast`.
On Sat, Feb 12, 2022 at 09:37:56AM +, IGotD- via Digitalmars-d-learn wrote:
> On Saturday, 12 February 2022 at 00:41:22 UTC, H. S. Teoh wrote:
[...]
> >
> > final class Boxed(T) {
> > T payload;
> > alias payload this; // caveat: probably not a good idea in general
> > this
On Saturday, 12 February 2022 at 00:41:22 UTC, H. S. Teoh wrote:
How about this?
final class Boxed(T) {
T payload;
alias payload this; // caveat: probably not a good idea in
general
this(T val) { payload = val; }
}
Boxed!int i = new Boxed!int(123);
int j = i; // hoo
On Sat, Feb 12, 2022 at 12:27:34AM +, IGotD- via Digitalmars-d-learn wrote:
> If you want to store a value type on the heap in D you just use "new"
> and a pointer to the type. The same thing in C# would be to wrap the
> value type into an object. However when you do that automatic
> conversion
If you want to store a value type on the heap in D you just use
"new" and a pointer to the type. The same thing in C# would be to
wrap the value type into an object. However when you do that
automatic conversion without a cast seems not to be possible (C#
also have a dynamic type that might sol