Skip to content

ambiguous call #3

Open
Open

Description

@bjornrommel

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?

Activity

  1. Cryoris commented on Mar 17, 2022

    @Cryoris
    Owner

    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.

  2. bjornrommel commented on Mar 20, 2022

    @bjornrommel
    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.

  3. Cryoris commented on Apr 26, 2022

    @Cryoris
    Owner

    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 🙂

  4. bjornrommel commented on Apr 26, 2022

    @bjornrommel
    Author
  5. bjornrommel commented on Oct 11, 2022

    @bjornrommel
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions