HACKER Q&A
📣 djmips

How to learn a C++ codebase with templates


What are some tools that can be used when starting on a new C++ codebase that makes extensive use of templates. I find it impenetrable compared to code I've worked on in the past. Also there are no comments or documentation... Would a LLM tool help?


  👤 xodjmk Accepted Answer ✓
Out of curiosity, I took a simple C++ template from my code and used the following prompt with chatGPT3:

Write a non-template C++ function using uint16_t to replace the following function: < copy & paste my template >

It worked, though I would never use the code it generated as is or without verifying.

Will this help with a large codebase?? As an alternative way of thinking, if the codebase really used templates correctly, the codebase should be simpler and less complex. If you study and understand one function generating template, then you should understand how this template will work for all cases. But I realize that's the ideal, and templates can get buckwild.


👤 djmips
In the past when starting on a new C++ codebase I would read code (obviously) and step through code but the extensive use of templates makes stepping through the code worse than stepping through assembly code!