Template Support

60 views
Skip to first unread message

Steve Browne

unread,
Feb 29, 2012, 6:23:44 PM2/29/12
to mono-cxxi
So I want to work on implementing template support, but I haven't
decided on how to implement them yet. I was hoping maybe if someone
else had any ideas they could post them. I'll mention a few things
I've thought about so far.

I would *REALLY* like to support them virtually the same way as
generics. I realize they're different, but it would be more natural to
do it that way because of the similar concepts and syntax involved in
both. There's a few problems with the gccxml generated output to
mention. Basically only template types that are actually used in the
header will be output. This means there has to be an instance of the
template with that type or it must be referenced as a parameter or
something.

Also because templates are only generated for those types that
actually get use we would have to prevent using other types on
generics. Then finally the gccxml output doesn't differentiate between
Template<T>::Add(T value) and Template<T>::Add(double value) where T
is a double. This means there's no way to determine which parameters
use the template types etc.

So the way I'd like to do it would be something like this:
// NOTE: Not possible because we can't determine which parameters
should be template types
// Also I'd love for AdderTemplate<T> to be internal or hidden somehow
if possible rather than abstract
public class AdderTemplateOfInt : AdderTemplate<int> {}
public class AdderTemplateOfDouble : AdderTemplate<double> {}
public class AdderTemplateOfFloat : AdderTemplate<float> {}
public abstract class AdderTemplate<T>
{
// Insert implementation here
// Maybe throw an exception if inherited from using an unsupported
type at runtime
}

However, due to gccxml limitations for now I think the only way I'll
be able to do it is something like this:
[TemplateClass("AdderTemplate<int>")]
public class AdderTemplateOfInt
{
// Insert implementation here
}
[TemplateClass("AdderTemplate<double>")]
public class AdderTemplateOfDouble
{
// Insert implementation here
}

Anyone else have any ideas or thoughts?

Steve Browne

unread,
Mar 3, 2012, 2:42:43 AM3/3/12
to mono-cxxi
Well I have some basic support in there now. Although I don't know how
useful it's really going to be since exporting template types has
several challenges to begin with. Either way in basic situations like
the unit tests we have they're working in both MSVC and Itanium ABIs.

I tried creating some tests using a static template function, but I
wasn't able to get MSVC to not inline it. Maybe I'll try again later.
Reply all
Reply to author
Forward
0 new messages