August 04, 2004 Re: Typedef blocks | ||||
---|---|---|---|---|
| ||||
Posted in reply to pragma | "pragma" <EricAnderton at yahoo dot compragma_member@pathlink.com> wrote in message news:cer1f8$5kj$1@digitaldaemon.com... > In article <cequ4v$312p$1@digitaldaemon.com>, Ivan Senji says... > >What about soemthing like this: > > > >template AttributeSet(T,V) > >{ > > typedef T[V] AttributeSet; > > > > T getAttribute(AttributeSet a, V x) > > { > > writefln(x); > > return a[x]; > > } > >} > > > >void main () > >{ > > mixin AttributeSet!(char[],char[]) AttributeSetX; > > AttributeSetX.AttributeSet set; > > set["name"] = "foo"; > > set["color"] = "red"; > > set.getAttribute("BLA"); > >} > > Or better yet: > > alias AttributeSet!(char[],char[]).AttributeSet ASet; > Aset set; This is what i did at first too, but there wasn't a way to call set.getAttrubute in a simple way! Or have you found a way! > > Which should make things a little more transparent, especially when passing it > around from function to function. > > >> # alias WindowEventDelegate void delegate(char[]); > >> # typedef WindowEventDelegate[] WindowEvent; > >> # > >> # void opCall(char[] reason){ > >> # foreach(WindowEventDelegate d; this){ > >> # d(reason); > >> # } > >> # } > >> > >> But of course we cannot override operators in the global scope, so > >/something/ > >> is still needed. But it does work as long as you invoke using .opCall > >verbatim. > > > >Or maby a class solution would be best? > > I'd agree, except in order to do the same /exact/ thing as my proposed typedef > block, you're looking at reproducing the behavior in roughly 12 methods and > members that are already available in char[char[]]. I know that using a class > is the best way ahead for now, but extending typedef this way leads to much more > maintainable code IMO. > > - Pragma > > |
Copyright © 1999-2021 by the D Language Foundation