gdb: how do you get the max value of a std::vector<float>?

Trevor Boyd Smith

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).

StoryTeller - Unslander Monica

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.

edited at
0

Comments

0 comments
Login to comment

Related

How do you iterate a function in gdb with various inputs until you get a successful return value

(SQL) How do you select a max float value along with other datatypes values within a query?

How to find Max value of second element of std::pair in std::vector?

How to get float value from object in Vector?

How do you get the max value for a foreign key value in models.py file?

How do you get the magnitude of a vector in Numpy?

How do you get the magnitude of a vector in Numpy?

How do you find max/min of a non-numeric vector?

How do you assign a pointer to an existing variable in a std::vector?

How do I get the max value of scrollLeft?

How do you find the largest float below some value?

How do you get the selected value of a Spinner?

How do you get the value of a "embed"?

How do I get the max element of a std::unordered_map?

How do you get the component of a vector in the direction of a ray

c++ How do I .get() std::future out of a vector?

How do you convert a `std::string` hex value to an `unsigned char`

Laravel collection - get max value as float/int

how to print std::map value in gdb

how to get max value

How to speedup my Libsvm vector to std::vector<float> conversion?

how do you get a specific value searched by a value in dataframes?

How do you get Math.max to give you the variables name

R: how do you apply a function to a vector and get a vector of different length?

How do you declare a global std::vector 2d array across multiple files? c++

How to find max value for Double and Float in Swift

How do i get all rows with max value in laravel eloquent?

How do i get Min and Max value of Bootstrap slider?

How do I get the corresponding column value for MAX function?