简体   繁体   English

如何使用Boost Python将C ++ bool转换为Python布尔值?

[英]How to convert from C++ bool to Python boolean with Boost Python?

I've been trying to make a conversion function from C++ types (like std::string and int) to convert to boost::python::object but the Boost docs about objects didn't specify anything about bools. 我一直在尝试从C ++类型(例如std :: string和int)制作一个转换函数,以转换为boost :: python :: object,但是关于对象Boost文档没有指定任何关于bool的东西。

boost::python::object convert_to_python_bool(bool input_bool) {
    return boost::python::boost_python_bool_type(input_bool);
}

I found out you have to explicitly convert to boost::python::object and there is no special class like boost::python::bool_ or anything like that: 我发现您必须显式转换为boost :: python :: object,没有像boost :: python :: bool_这样的特殊类或类似的东西:

boost::python::object convert_to_python_bool(bool input_bool) {
    return boost::python::object(input_bool);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM