Thread overview
String pasting / symbol construction?
Jan 27, 2007
Bill Baxter
Jan 27, 2007
Tom S
Jan 27, 2007
BCS
January 27, 2007
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
January 27, 2007
Bill Baxter wrote:
> There's still no way to do that, right?
> Any good workarounds?

Nope. But if someone is counting votes, I'd like that functionality as well.
January 27, 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