implot icon indicating copy to clipboard operation
implot copied to clipboard

Lambda support is advertised and documented, but apparently not implemented.

Open ATell-SoundTheory opened this issue 2 years ago • 4 comments

In ImPlot 0.14, PlotLineG (or any other getter-enabled function) does not implement a lambda getter argument. The only getter defined is a c-style function pointer named ImPlotGetter and lambdas are not convertible to c-style function pointers. Is this an oversight in the documentation or the implementation?

ATell-SoundTheory avatar Feb 07 '23 21:02 ATell-SoundTheory

they are 'convertible' when they have this signature: auto my_lambda = [](int idx, void*) { ... } but it confused me as well, and could be improved imo - see #445

nuuSolutions avatar Feb 08 '23 13:02 nuuSolutions

The conversion of non-capturing lambdas to function pointers is a compiler feature though, and not a library feature. So the library de-facto does not support lambdas.

ATell-SoundTheory avatar Feb 08 '23 13:02 ATell-SoundTheory

What would be your use-case? your make lambdas which capture your data and return the transformed data you want to plot? or captureless lambdas taking a data* and index? or third option?

nuuSolutions avatar Feb 10 '23 20:02 nuuSolutions

Your first option, e.g.,

auto getter = [t, y](int idx, void *unused) -> ImPlotPoint {
                return ImPlotPoint(t[idx], y[idx].x);
};

instead of having to create a struct containing t and y, and passing in a pointer to that struct.

prlw1 avatar Sep 14 '23 15:09 prlw1