String pasting / symbol construction?

BCS ao at pathlink.com
Sat Jan 27 10:47:06 PST 2007


Reply to Bill,

> Just checking ... there's still no way to construct symbols (maybe
> tokens is the right word?) at compile time is there?
> 
> For instance if I want to have something like
> 
> template funcs(char[] suffix) {
> alias function1##suffix function1;
> alias function2##suffix function2;
> alias function3##suffix function3;
> }
> resulting in
> 
> funcs!("f").function1()
> 
> being equivalent to the call
> 
> function1f()
> 
> There's still no way to do that, right?
> Any good workarounds?
> (In this case I'd actually like to take 3 strings and paste em
> together
> like that to make a function name).
> --bb
> 

not directly but checkout my dparse lib (dource -> projects -> scrapple -> 
dparse) it uses template specializations to generate and refer to custom 
symbol names. It's limited (no forward reference and everything must be declared 
in the same scope) but I works for the most part.

Allowing template specializations to overload from different scopes and allowing 
lazy lookup or forward referencing of specializations* would make this vary 
powerful. 

* IIRC these aren't in the spec but DMD seems to handle them some way




More information about the Digitalmars-d-learn mailing list