epezent / implot

Immediate Mode Plotting
MIT License
4.55k stars 503 forks source link

`ImPlot::PlotLineG` forces data to be mutable #493

Open ChrisThrasher opened 1 year ago

ChrisThrasher commented 1 year ago

https://github.com/epezent/implot/blob/cc5e1daa5c7f2335a9460ae79c829011dc5cef2d/implot.h#L856

The signature for ImPlot::PlotLineG uses a void* which implies that the data it is reading is mutable. This means you cannot use something like a const std::vector<double> and call .data() to get a pointer to the first element since a const double* is not implicitly convertible to a void*. I'd like this to be changed to a const void* which implies a slight change to the signature of ImPlotGetter to reflect this extra const.

This would not be an API break except for those who are using PlotLineG to mutate data while ImPlot is reading it.

If accepted, I'm willing to help implement this. There are other APIs that behave similarly that ought to receive this same treatment so the PR would touch more interfaces than simply PlotLineG.

epezent commented 11 months ago

This means you cannot use something like a const std::vector and call .data()

Is this a specific case for you? If so, why not just use the regular PlotLine with const T*?

ChrisThrasher commented 11 months ago

Because I need PlotLineG because my data is in a struct that must be unpacked via a getter function. My vector of structures must be kept non-const just for the sake this API which feels like a bug to me.