I am debugging some C++ code and I have a really large std::vector<floating_point_type>
(float
or double
). In C++ code when I want the max value of the std::vector
I can just use std::max_element()
. So in gdb
I tried to use the same code, but I got an error.
In gdb
I used call std::max_element(x)
and got an error message No symbol "max_element" in namespace "std".
Is there any way to get the max value of a vector in gdb
?
I would also appreciate an explanation for why my attempt at using std::max_element
was not working (perhaps std::max_element
a header-only or inline function).
std::max_element
is a function template, not a function. You are asking GDB to do template argument deduction and the whole shebang involved with calling a template function without specifying arguments. It can't do that, naturally, it's not a full fledged compiler.
As far as I know any solution, from the simplest to the most complex, will require of you to modify your source in such a way that std::max_element
is instantiated for the iterator types of your vector. So you may as well add "debug only" code that computes the maximum element and stores it into a local variable.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments