将空集传递给类型为const std :: set <std :: string>&my_set_that_can_be_empty的函数

时间:2019-12-05 21:31:59

标签: c++ std pybind11

我正在尝试将一组字符串传递给c ++函数。很好但是,在某些情况下,该集合为空,并且出现类型错误。

这可能是c ++问题,也可能是我通过pybind11调用了python函数来连接它。

任何关于如何优雅解决问题的建议都将受到高度赞赏。

我在这里发布了一个示例:

https://github.com/dickreuter/neuron_poker/blob/master/tests/test_montecarlo_cpp.py#L44

def test_montecarlo4():
    """Montecarlo test"""
    my_cards = {'AS', 'KS'}
    cards_on_table = {}
    expected_results = 66.1 + 1.6
    players = 2
    _runner(my_cards, cards_on_table, players, expected_results)


def _runner(my_cards, cards_on_table, players, expected_result):
    """Montecarlo test"""
    # if len(cards_on_table) < 3:
    #     cards_on_table = {'null'}
    equity = calculator.montecarlo(my_cards, cards_on_table, players, 5000)
    assert equity == pytest.approx(expected_result, abs=1)

呼叫 https://github.com/dickreuter/neuron_poker/blob/master/tools/Montecarlo.cpp#L266

double montecarlo(const std::set<std::string>& my_cards, const std::set<std::string>& cards_on_table, const int number_of_players, const int iterations) {

导致:

E       TypeError: montecarlo(): incompatible function arguments. The following argument types are supported:
E           1. (arg0: Set[str], arg1: Set[str], arg2: int, arg3: int) -> float

0 个答案:

没有答案