digitalmars.D.learn - Voldemort type for mixin template.
When I try add some sub type for struct with mixin template, seems there is no way to hidden the private type. Is there a way to hidden type from mix template like Voldemort type ? fake code: mix template TypeX () { alias This = typeof(this); static struct Unique { This* _ptr ; } static struct Helper { private Unique data; } alias TypeX = { alias PublicName = Helper ; } } struct Node { mixin TypeX!(); PublicName helper; }
Jan 11 2018
On Thursday, 11 January 2018 at 08:56:11 UTC, ChangLong wrote:When I try add some sub type for struct with mixin template, seems there is no way to hidden the private type. Is there a way to hidden type from mix template like Voldemort type ? fake code: mix template TypeX () { alias This = typeof(this); static struct Unique { This* _ptr ; } static struct Helper { private Unique data; } alias TypeX = { alias PublicName = Helper ; } } struct Node { mixin TypeX!(); PublicName helper; }Hi, can you explain a bit more? The question is not entirely clear to me. Can you mixin a struct of type PublicName and just hide everything in there? mixin template TypeX() { struct PublicName { private alias This = typeof(this); private struct Unique { This* _ptr; } private Unique _data; alias _data this; } } void main(string[] args) { mixin TypeX; PublicName helper; helper._ptr.writeln; } Cheers
Jan 11 2018
On Thursday, 11 January 2018 at 21:30:43 UTC, aliak wrote:On Thursday, 11 January 2018 at 08:56:11 UTC, ChangLong wrote:If PublicName is complex type, require has some private type information. there is noway to hidden the private type from the scope of mixin. the purpose is hidden helper._ptr from main function to avoid name conflict. I try use mixin fo modify struct to allow it has some kind zero cost abstract, or memory manage function. since the system is complex it will import a lot symbol into the class. I has to put the mix template into struct, since I has to add member with type from mix template. and I also want to avoid access ref_count from the struct body(and a lot other name conflict)When I try add some sub type for struct with mixin template, seems there is no way to hidden the private type. Is there a way to hidden type from mix template like Voldemort type ? fake code: mix template TypeX () { alias This = typeof(this); static struct Unique { This* _ptr ; } static struct Helper { private Unique data; } alias TypeX = { alias PublicName = Helper ; } } struct Node { mixin TypeX!(); PublicName helper; }Hi, can you explain a bit more? The question is not entirely clear to me. Can you mixin a struct of type PublicName and just hide everything in there? mixin template TypeX() { struct PublicName { private alias This = typeof(this); private struct Unique { This* _ptr; } private Unique _data; alias _data this; } } void main(string[] args) { mixin TypeX; PublicName helper; helper._ptr.writeln; } Cheers
Jan 11 2018