www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.sumtype nested SumTypes

reply NonNull <non-null use.startmail.com> writes:
I am defining a new value type (small struct) from some old value 
types that are already `SumType`s.

So I want to have some `SumType`s as some of the alternative 
types in another `SumType`.

How  how efficient this is, including space efficient?
Jan 22
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Monday, 22 January 2024 at 16:16:56 UTC, NonNull wrote:
 I am defining a new value type (small struct) from some old 
 value types that are already `SumType`s.

 So I want to have some `SumType`s as some of the alternative 
 types in another `SumType`.

 How  how efficient this is, including space efficient?
Without knowing what you are doing, this sounds like a bad idea, i suggest to revise your design
Jan 22
parent reply NonNull <non-null use.startmail.com> writes:
On Monday, 22 January 2024 at 16:35:39 UTC, ryuukk_ wrote:
 On Monday, 22 January 2024 at 16:16:56 UTC, NonNull wrote:
 I am defining a new value type (small struct) from some old 
 value types that are already `SumType`s.

 So I want to have some `SumType`s as some of the alternative 
 types in another `SumType`.

 How  how efficient this is, including space efficient?
Without knowing what you are doing, this sounds like a bad idea, i suggest to revise your design
I'd like SumType to combine the implicit tags so there's only one tag.
Jan 22
parent reply Paul Backus <snarwin gmail.com> writes:
On Monday, 22 January 2024 at 21:11:17 UTC, NonNull wrote:
 I'd like SumType to combine the implicit tags so there's only 
 one tag.
SumType does not do this automatically (because sometimes you might want to keep the inner SumTypes separate), but you can do it yourself like this: alias A = SumType!(X, Y); alias B = SumType!(Z, W); alias C = SumType!(A.Types, B.Types);
Jan 22
parent NonNull <non-null use.startmail.com> writes:
On Monday, 22 January 2024 at 21:36:47 UTC, Paul Backus wrote:
 SumType does not do this automatically (because sometimes you 
 might want to keep the inner SumTypes separate), but you can do 
 it yourself like this:

     alias A = SumType!(X, Y);
     alias B = SumType!(Z, W);
     alias C = SumType!(A.Types, B.Types);
Very nice!
Jan 26