1

I'm calling a pyd (.dll) that I created in c++ with boost-python as follows from python:

equity = calculator.montecarlo({"3H", "3S"}, {"8S", "4S", "QH", "8C", "4H"}, 2, 10000)

but it complains that the signature is just a set but not a set of strings. Any suggestions what I can do about it are highly appreciated.


    EquityCalculatorMontecarlo.montecarlo(set, set, int, int)
    did not match C++ signature:
        montecarlo(class std::set<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >, class std::set<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >, int, int)
Nickpick
  • 6,163
  • 16
  • 65
  • 116
  • You're passing in Python `set` objects, but the function expects c++ `std::set` objects. AFAIK there's no out-of-the-box support for STL containers in Boost.Python. The simplest solution is to add a wrapper function that takes `boost::python::object` arguments instead, converts them to c++ sets (along with verification that they python sets indeed contain only strings), and then calls the original `montecarlo` function. – Dan Mašek Nov 30 '19 at 20:42
  • For example: https://pastebin.com/7PHkV2CA – Dan Mašek Nov 30 '19 at 21:14
  • I see, isn't that almost as complicated as just using the python ctypes module? – Nickpick Dec 01 '19 at 14:10
  • Haven't tried that, but from what I've read, using ctypes to call a c++ function (and one that takes c++ collections by value/const ref as input) is at best non-trivial. if it was a C API, then sure. | You could have a look at pybind11 -- I haven't had a chance to try it yet, but it has been recommended to me as a more modern alternative to boost python. They might support this out of the box, or in an easier manner. | I'll see if I can figure out something with custom converters, but that's far more involved that the simple solution presented above. – Dan Mašek Dec 01 '19 at 18:51
  • yes pybind11 would be great but it doesn't compile on windows: https://github.com/pybind/pybind11/issues/2014 – Nickpick Dec 01 '19 at 19:06
  • Oh, OK. Which version were you trying to build the tests for? (It's a header-only library so you don't really need to build anything to use it) | Thanks for giving me the impetus to check pybind further -- it does have support for C++ collections it seems. Nice. | I"m on a train right now, but i'll have a further look at pybind when I get home and try to figure out why you can't seem to be able to build the tests. – Dan Mašek Dec 01 '19 at 21:18
  • I just cloned the latest version from github – Nickpick Dec 02 '19 at 12:32
  • Hmmm, odd. Works fine here (MSVS 2015), both master as well as the v2.4.3 release tag. – Dan Mašek Dec 02 '19 at 19:36
  • I'm using vs2019. Could that be the problem? – Nickpick Dec 02 '19 at 23:41

0 Answers0