A tool to view instantiated templates?

S

Steven T. Hatton

If I understand correctly, a template is translated into its source
equivalence, either explicitly, or implicitly. It seems to me, a tool that
would show me that intermediate form of the template would be very useful
in understanding what my templates are actually doing. Is there such a
tool?

G++ may support this, but I didn't see a way to do it when I looked in the
documentaton. I'll ask on a gcc newsgroup and see if I can get an answer
about that specific issue.
 
V

Victor Bazarov

Steven said:
If I understand correctly, a template is translated into its source
equivalence, either explicitly, or implicitly. It seems to me, a tool that
would show me that intermediate form of the template would be very useful
in understanding what my templates are actually doing. Is there such a
tool?

G++ may support this, but I didn't see a way to do it when I looked in the
documentaton. I'll ask on a gcc newsgroup and see if I can get an answer
about that specific issue.

I don't know of such a tool. But how would it be "very useful"? What
in the template code don't you see that the tool would show you? The
actual types? Write your template so that the type argument is named
as one of the supported types, say 'CHAR' for 'char' or 'INT' for 'int'.
It'll be quite readable (better than 'T'). The actual values? Well,
the same solution could work: name the values _1 and _0 or something
like it. Or do you need to see recursive template expansion to see what
happens when you do

template<int _1> class S { blah S<_1 - 1>; };
template<> class S<0> { blahblah; };

? Well, that's a bit tricky. I, for one, would only use that "template
viewing tool" to see the expanded recursive templates. However, I would
be very surprised if such tool would be provided by a company who doesn't
have a compiler because rules concerning templates are complicated and if
you can get them right, you're more than half-way in writing a compiler.
OTOH, if you have enough people to write a compiler, that's what your
efforts would be concentrated on... IMHO.

V
 
E

E. Robert Tisdale

Steven said:
If I understand correctly, a template is translated into its source
equivalence, either explicitly, or implicitly. It seems to me that,
a tool that would show me that intermediate form of the template
would be very useful in understanding what my templates are actually doing.
Is there such a tool?

G++ may support this, but I didn't see a way to do it
when I looked in the documentaton. I'll ask on a gcc newsgroup
and see if I can get an answer about that specific issue.

C++ template code is more difficult to read, debug and maintain.
I don't know of any tools (g++ or otherwise)
that will help you display the instantiations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top