digitalmars.D.learn - can I get public alias to private templates?
- BCS (17/17) May 17 2007 I have a struct like this
- Chris Nicholson-Sauls (13/37) May 17 2007 I don't know of any way to expose public names for private things in qui...
- BCS (4/19) May 17 2007 Yeah, I guess I could do that. But I also have a bunch of other stuff th...
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.
May 17 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
May 17 2007
Reply to Chris Nicholson-Sauls,
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.)
Yeah, I guess I could do that. But I also have a bunch of other stuff that
would have to be checked. I guess I could make it all public and then make
threats against the lives on anyone who uses the template directly. :b
May 17 2007








BCS <ao pathlink.com>