is expression for template structs/classes instances?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Dec 21 11:46:45 PST 2010
On Tuesday, December 21, 2010 02:57:45 d coder wrote:
> > I do know the template. I will try out your solution. Will let you
> > know if I face issues.
>
> Simen
>
> It works perfect, And this is exactly what I was looking for. If you
> see my original post, I also thought this form of "is" expression
> should work. Just could not get around to the right syntax.
>
> With your help it is working now. I am using a slightly more elaborate
> check which is obvious but I am writing it here to just let the list
> know.
>
> static if ( is( typeof(foo) f == S!T, T : int) ) {
> // foo is an object of type S!T
> // where T is convertible to int
> }
Yes, that sort of thing works. The problem is when you want to know whether an
arbitrary type is an instantiation of a particular template. For instance, if
you have
struct S(T)
{
}
struct Q(T)
{
}
and you pass S!int to Q - Q(S!int) - Q sees S!int is a specific type, not an
instantiation of S, so it's difficult to have a template constraint checking that
the type passed to Q is an instantiation of S. However, if you know exactly
which instantiation that you're checking for, then it's relatively easy.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list