Thread overview | |||||
---|---|---|---|---|---|
|
February 18, 2011 Checking if something is a template specialization? | ||||
---|---|---|---|---|
| ||||
If I have class Bar(T) { } void foo(Y)() { ... } Is there a way to check inside foo() that Y is in some way an instantiation of Bar? Is there a way to find WHICH instantiation it is? |
February 18, 2011 Re: Checking if something is a template specialization? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Eskapp | On Fri, 18 Feb 2011 02:02:51 +0000, Sean Eskapp wrote:
> If I have
>
> class Bar(T)
> {
> }
>
> void foo(Y)()
> {
> ...
> }
>
> Is there a way to check inside foo() that Y is in some way an instantiation of Bar? Is there a way to find WHICH instantiation it is?
void foo(Y)()
{
static if (is(Y Z == Bar!Z))
{
// Here, Z is now an alias to whichever type Bar is
// instantiated with.
}
else
{
// Z is invalid here.
}
}
|
February 18, 2011 Re: Checking if something is a template specialization? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars T. Kyllingstad | == Quote from Lars T. Kyllingstad (public@kyllingen.NOSPAMnet)'s article
> On Fri, 18 Feb 2011 02:02:51 +0000, Sean Eskapp wrote:
> > If I have
> >
> > class Bar(T)
> > {
> > }
> >
> > void foo(Y)()
> > {
> > ...
> > }
> >
> > Is there a way to check inside foo() that Y is in some way an instantiation of Bar? Is there a way to find WHICH instantiation it is?
> void foo(Y)()
> {
> static if (is(Y Z == Bar!Z))
> {
> // Here, Z is now an alias to whichever type Bar is
> // instantiated with.
> }
> else
> {
> // Z is invalid here.
> }
> }
Perfect, thanks!
|
Copyright © 1999-2021 by the D Language Foundation