Skip to content

ambiguous call #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bjornrommel opened this issue Jan 28, 2022 · 5 comments
Open

ambiguous call #3

bjornrommel opened this issue Jan 28, 2022 · 5 comments

Comments

@bjornrommel
Copy link

When compiling a standard example from readthedocs,

#include
#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;
int main() {
std::vector x = {1, 2, 3, 4};
std::vector y = {1, 4, 9, 16};
plt::plot(x, y,"r*");
plt::show();
}

on VisualStudio22 with the ISO C++20 flag and native Python 3.10, I get

Screenshot 2022-01-26 172910

Apparently, the compiler cannot decide between

// @brief standard plot function supporting the args (x, y, s, keywords) // line 519
// ...
template <typename VectorX, typename VectorY>
bool plot(const VectorX &x, const VectorY &y, const std::string &s = "",
const std::map<std::string, std::string> &keywords = {}) {
return detail::plot_base(detail::_interpreter::get().s_python_function_plot,
x, y, s, keywords);
}

and

// enable plotting of multiple triples (x, y, format) // line 1953
template <typename A, typename B, typename... Args>
bool plot(const A &a, const B &b, const std::string &format, Args... args) {
return plot(a, b, format) && plot(args...);
}

As I understand, correct me if I'm wrong, there a several constructors, each of which is designed to fall through to the first one above, the one that finally calls plot_base. So, I renamed all constructors but the first one above plot1, and my code now successfully calls plt::plot1 ..... Of course, messing with your library and using non-standard calls on my side is not a proper solution. Rename the fall-through constructor, and I haven't even tested similarily overloaded functions?

@Cryoris
Copy link
Owner

Cryoris commented Mar 17, 2022

That's an interesting failure! It's been a while since I was actively using and maintaining this code, but I think the second signature in your comment is to allow chaining of multiple datasets e.g.

plot(x1, y1, "r*", x2, y2, "b--", ...);

I'm a little confused as to why the compilation fails for you, is there an option you can force the compiler to choose one of the options if there are multiple? Both would work in this case.

If that's not possible, I'd rename or remove the second function. It's just for convenience to allow multiple datasets in a single function call, I think it's justified (and probably cleaner too) to have one line per dataset.

@bjornrommel
Copy link
Author

No, no chaining involved! The compiler cannot decide between the two overloaded alternatives because one of them defaults missing arguments.

Please, check which function is supposed to catch plot(x, y, string)? The first alternative catches plot(x, y, string, keyword), which works because keyword defaults to {}; so, that's valid. The second alternatives catches plot(x,y,string), which is also valid. Here, string and format are meant to refer to the same argument.

@Cryoris
Copy link
Owner

Cryoris commented Apr 26, 2022

Please, check which function is supposed to catch plot(x, y, string)?

The first one. The second one is only there to enable the chaining which you don't need it seems 🙂

@bjornrommel
Copy link
Author

bjornrommel commented Apr 26, 2022 via email

@bjornrommel
Copy link
Author

bjornrommel commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants