Let's say I have a templated class:
template <typename T>
class A
{
public:
void foo()
{
int i = 0; //breakpoint here only for type A<int>
}
}
Can i somehow add a breakpoint, in Visual studio, that will only break inside foo
for a certain instantiation ?
Like only for A<int>::foo
?
Let's assume I have 100's of templated A instantiations with different types.
Edit:
I do know how to make instantiations in a way that i could specialize a certain type.
The question is can i do it without specialization?
Right-click the breakpoint symbol and select Conditions (or press Alt + F9, C). Or hover over the breakpoint symbol, select the Settings icon, and then select Conditions in the Breakpoint Settings window.
To instantiate a template function explicitly, follow the template keyword by a declaration (not definition) for the function, with the function identifier followed by the template arguments. template float twice<float>(float original); Template arguments may be omitted when the compiler can infer them.
In order for any code to appear, a template must be instantiated: the template arguments must be provided so that the compiler can generate an actual class (or function, from a function template).
I found it.
Just put a breakpoint in the line you want (I'll show an example with std::shared_ptr<>).
Then go to the Breakpoints window and notice that when it breaks, there's a little +
next to the breakpoint that will open all the different instantiations.
The line in bold is the breakpoint that is currently active.
Now, unfortunately, the Breakpoints window doesn't show you the actual template instantiation.
But, you can use the call stack to see which instantiation is currently used.
Or, you can right click on each of the breakpoints, and choose "Go To Disassembly".
This may give you a hint as to the actual template instantiation. Then you can choose which breakpoints and for which type you want to keep active.
Edit: You could also add the Function column to the Breakpoints window and see the actual template function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With