Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-29 Thread aliak via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 15:37:11 UTC, SimonN wrote: On Tuesday, 27 March 2018 at 15:28:40 UTC, jmh530 wrote: static if (isMutable!T) bag[0] = rhs; else bag = [rhs]; I like this idea. I'd even take it a step futher: When T is a pointer or class

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread SimonN via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 15:28:40 UTC, jmh530 wrote: static if (isMutable!T) bag[0] = rhs; else bag = [rhs]; I like this idea. I'd even take it a step futher: When T is a pointer or class reference, then we can put the reference on the stack

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 13:51:20 UTC, jmh530 wrote: How about: [snip] I can kind of like this more, but after re-reading your original post I'm not sure it really resolves your issue: struct Optional(T) { import std.traits : isMutable; T[] bag; this(T t) inout {

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread SimonN via Digitalmars-d-learn
On Monday, 26 March 2018 at 14:17:03 UTC, Jonathan M Davis wrote: Rebindable does is pretty questionable as far as the type system goes, but it does what it does by forcing pointer semantics on a class reference, so the point is arguable. Yeah, I've always assumed that Rebindable cannot be

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 13:02:50 UTC, aliak wrote: Hmm, now that I'm explicitly trying to produce it, I feel I maybe using inout incorrectly? struct Optional(T) { T[] bag; this(T t) { bag = [t]; } } struct S { Optional!(inout(int)) f() inout { return

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread aliak via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 11:57:28 UTC, jmh530 wrote: On Tuesday, 27 March 2018 at 06:26:57 UTC, aliak wrote: [snip] By the by, how come inout has to be stack based and const/immutable/mutable doesn't? Isn't inout just one of those depending on context? Example? Hmm, now that I'm

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 06:26:57 UTC, aliak wrote: [snip] By the by, how come inout has to be stack based and const/immutable/mutable doesn't? Isn't inout just one of those depending on context? Example?

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread aliak via Digitalmars-d-learn
On Monday, 26 March 2018 at 11:19:31 UTC, Seb wrote: On Monday, 26 March 2018 at 10:13:08 UTC, Simen Kjærås wrote: On Monday, 26 March 2018 at 09:46:57 UTC, Nicholas Wilson wrote: Have a look at Rebindable: https://dlang.org/phobos/std_typecons.html#rebindable Allow me to quote from aliak's

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread aliak via Digitalmars-d-learn
On Monday, 26 March 2018 at 21:17:10 UTC, jmh530 wrote: On Sunday, 25 March 2018 at 21:26:57 UTC, aliak wrote: Hi, I have this optional type I'm working on and I've run in to a little snag when it comes to wrapping an immutable. Basically what I want is for an Optional!(immutable T) to still

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread aliak via Digitalmars-d-learn
On Sunday, 25 March 2018 at 23:00:11 UTC, Simen Kjærås wrote: On Sunday, 25 March 2018 at 21:26:57 UTC, aliak wrote: struct Optional(T) { Unqual!T value; opAssign(T t) { value = cast(Unqual!T)(t); } } Consider this case: Optional!(immutable int) a = some(3); immutable int* p = a =

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread jmh530 via Digitalmars-d-learn
On Sunday, 25 March 2018 at 21:26:57 UTC, aliak wrote: Hi, I have this optional type I'm working on and I've run in to a little snag when it comes to wrapping an immutable. Basically what I want is for an Optional!(immutable T) to still be settable to "some" value or "no" value because the

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 26, 2018 10:13:08 Simen Kjærås via Digitalmars-d-learn wrote: > On Monday, 26 March 2018 at 09:46:57 UTC, Nicholas Wilson wrote: > > Have a look at Rebindable: > > https://dlang.org/phobos/std_typecons.html#rebindable > > Allow me to quote from aliak's post: > > what I'm looking

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Seb via Digitalmars-d-learn
On Monday, 26 March 2018 at 10:13:08 UTC, Simen Kjærås wrote: On Monday, 26 March 2018 at 09:46:57 UTC, Nicholas Wilson wrote: Have a look at Rebindable: https://dlang.org/phobos/std_typecons.html#rebindable Allow me to quote from aliak's post: what I'm looking for is a Rebindable

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 26 March 2018 at 09:46:57 UTC, Nicholas Wilson wrote: Have a look at Rebindable: https://dlang.org/phobos/std_typecons.html#rebindable Allow me to quote from aliak's post: what I'm looking for is a Rebindable implementation that's for value types As can be surmised from the

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 25 March 2018 at 21:26:57 UTC, aliak wrote: Hi, I have this optional type I'm working on and I've run in to a little snag when it comes to wrapping an immutable. Basically what I want is for an Optional!(immutable T) to still be settable to "some" value or "no" value because the

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 25 March 2018 at 23:00:11 UTC, Simen Kjærås wrote: On Sunday, 25 March 2018 at 21:26:57 UTC, aliak wrote: struct Optional(T) { Unqual!T value; opAssign(T t) { value = cast(Unqual!T)(t); } } Consider this case: Optional!(immutable int) a = some(3); immutable int* p = a =

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-25 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 25 March 2018 at 21:26:57 UTC, aliak wrote: struct Optional(T) { Unqual!T value; opAssign(T t) { value = cast(Unqual!T)(t); } } Consider this case: Optional!(immutable int) a = some(3); immutable int* p = a = some(5); Clearly the above code shouldn't compile - you can't

Optional type - how to correctly reset a wrapped immutable T

2018-03-25 Thread aliak via Digitalmars-d-learn
Hi, I have this optional type I'm working on and I've run in to a little snag when it comes to wrapping an immutable. Basically what I want is for an Optional!(immutable T) to still be settable to "some" value or "no" value because the Optional wrapper itself is mutable. Optional!(immutable