can I get public alias to private templates?

Chris Nicholson-Sauls ibisbasenji at gmail.com
Thu May 17 18:24:44 PDT 2007


BCS wrote:
> I have a struct like this
> 
> Struct
> {
> void go(T)(T v){}
> }
> 
> and I want to only allow access to go with a finite set of parameters. 
> My first thought was this:
> 
> Struct
> {
> private void goT(T)(T v){}
> public alias goT!(int) go;
> public alias goT!(char) go;
> public alias goT!(byte) go;
> public alias goT!(float) go;
> }
> 
> But you cant tunnel through private with a public alias. Does anyone 
> known of a clean get somthing like this? Wrapper functions are not an 
> option.
> 
> 

I don't know of any way to expose public names for private things in quite that way, but 
you might consider something like this:

private void goT(T)(T v){
   static if (!(is(T == int) || is(T == char) || is(T == byte) || is(T == float))) {
     static assert (false, "...useful message...");
   }

   // ... code ...
}

Not super pretty, I know, but it should work.  It would be nice if there were a cleaner 
way of doing this for those cases where the list is long.  (I have something I would've 
liked to templatize in a similar fashion, but with about 10 types to support.)

-- Chris Nicholson-Sauls


More information about the Digitalmars-d-learn mailing list