-
Notifications
You must be signed in to change notification settings - Fork 101
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
Comments
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. |
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. |
The first one. The second one is only there to enable the chaining which you don't need it seems 🙂 |
Sorry, I think, you still have to make the alternative overloads unique,
but making each function call plot_base directly might be worth pursuing.
…On Tue, 26 Apr 2022 at 17:17, Julien Gacon ***@***.***> wrote:
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 🙂
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVGR7TUWCNHIHA6R2RO32DTVHACH3ANCNFSM5NAR4AUA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Yes, sure, but my compiler doesn't decide between equally valid
alternatives! You can overload a function, but each definition must be
unique, and they are not. You could either remove the ambiguity -- so, only
one parameter list matches -- or make every function call plot_base if
that's possible.
…On Tue, 26 Apr 2022 at 17:17, Julien Gacon ***@***.***> wrote:
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 🙂
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVGR7TUWCNHIHA6R2RO32DTVHACH3ANCNFSM5NAR4AUA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
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
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?
The text was updated successfully, but these errors were encountered: