digitalmars.D.learn - template alias parameters
- enuhtac (26/26) Apr 06 2011 Hi,
- Jesse Phillips (6/39) Apr 06 2011 I'm going to take a guess at the issue here. alias parameters are suppos...
Hi,
I'm playing around with template alias parameters. At the moment I'm
considering the following simple code:
struct A
{};
struct B( T )
{
T t;
};
struct C( alias T )
{
T t;
};
void main()
{
B!A a;
C!A b;
}
What exactly is the difference between a and b? Both seem to do the same
thing but obviously there is a difference as I cannot instanciate C with
buildin types as template parameter ("C!int c" results in "Error:
template instance C!(int) does not match template declaration C(alias T)").
The other question is: is there a possibility to distinguinish between
different "things" passed to a template alias paramter? - Like "isType",
"isVariable", "isLiteral", "isTemplate" ...
enuhtac
Apr 06 2011
enuhtac Wrote:Hi, I'm playing around with template alias parameters. At the moment I'm considering the following simple code: struct A {}; struct B( T ) { T t; }; struct C( alias T ) { T t; }; void main() { B!A a; C!A b; } What exactly is the difference between a and b? Both seem to do the sameNo difference.thing but obviously there is a difference as I cannot instanciate C with buildin types as template parameter ("C!int c" results in "Error: template instance C!(int) does not match template declaration C(alias T)").I'm going to take a guess at the issue here. alias parameters are supposed to bind to a symbol. Types aren't symbols, they aren't things that will have an address during runtime. I'm not exactly sure why the struct is excepted.The other question is: is there a possibility to distinguinish between different "things" passed to a template alias paramter? - Like "isType", "isVariable", "isLiteral", "isTemplate" ... enuhtacThere isn't a distinction for literal vs variable. I'm pretty sure. As mentioned you don't pass types to alias. And you probably wouldn't write a template that accepts a template or a variable. As it is a symbol you do get to use typeof() and the likes on it.
Apr 06 2011








Jesse Phillips <jessekphillips+D gmail.com>