-
boost python + lambda프로그래밍/c++ 2015. 11. 20. 11:01반응형
Boost python + lambda
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970// 실패script_dict["lobby_class"] =py::class_<lobby, boost::noncopyable>("lobby_class", py::no_init).def("name", &lobby::name).def("async_accept", [&lobby_](const std::string addr, unsigned short port){ … });// 실패auto async_accept = [&lobby_](const std::string& addr, unsigned short port){ .. }script_dict["lobby_class"] =py::class_<lobby, boost::noncopyable>("lobby_class", py::no_init).def("name", &lobby::name).def("async_accept", async_accept);// 실패std::function<void(lobby& self, const std::string& addr, unsigned short port)> async_accept_handler =[](lobby& self, const std::string& addr, unsigned short port){...};script_dict["lobby_class"] =py::class_<lobby, boost::noncopyable>("lobby_class", py::no_init).def("name", &lobby::name).def("async_accept", async_accept);// 성공void async_accept(lobby& l, const std::string addr, unsigned short port){…}script_dict["lobby_class"] =py::class_<lobby, boost::noncopyable>("lobby_class", py::no_init).def("name", &lobby::name).def("async_accept", async_accept);// 성공template < typename Self >void async_accept_handler(Self& self, const std::string& addr, unsigned short port){..}script_dict["lobby_class"] =py::class_<lobby, boost::noncopyable>("lobby_class", py::no_init).def("name", &lobby::name).def("async_accept", async_accept<lobby>);// 성공void (*async_accept)(lobby& self, const std::string& addr, unsigned short port) =[](lobby& self, const std::string& addr, unsigned short port){...};script_dict["lobby_class"] =py::class_<lobby, boost::noncopyable>("lobby_class", py::no_init).def("name", &lobby::name).def("async_accept", async_accept);cs 람다를 멤버함수로 정의해서 쓰려고 했는데 잘 안 되더라. 어쨌거나 하긴 했는데 썩 이쁘진 않다.
반응형'프로그래밍 > c++' 카테고리의 다른 글
vs2015 update1에서 c++17 module 기능 사용하기 (0) 2015.12.16 좀 인상 깊었던 mutable 키워드의 활용 (0) 2015.12.01 pyd 파일 없이 c++과 python 연동하기 (2) 2015.11.20 [c++] std::vector를 boost::python::list로 (0) 2015.11.19 std::map insert, emplace, try_emplace (0) 2015.11.06