pybind11C++ 的 Python 綁定
pybind11 可實現(xiàn) C++11 和 Python 之間的無縫操作。
pybind11 是一個輕量級的只包含一組頭文件的 C++ 庫,可以在 Python 中使用 C++ 類型。主要用于創(chuàng)建已有 C++ 代碼的 Python 封裝版本。其目的和語法類似于 Boost.Python 庫。為什么要創(chuàng)建這個項目的原因就是因為 Boost 。作者認為 Boost 很大很復雜。而目前的 C++11 兼容的編譯器使用已經(jīng)非常廣泛,所以希望開發(fā)一個更輕量級更具備兼容性的項目。
除去注釋之外,該項目的核心頭文件只有 2500 行左右代碼,依賴于 Python (2.7 或者 3.x) 和標準 C++ 庫。這么精簡的實現(xiàn)有賴于新的 C++11 語言特性。特別是元組、Lambda 函數(shù)以及可變模板。自從項目創(chuàng)建以來,其增長已經(jīng)超過了 Boost.Python。
核心特性
Functions accepting and returning custom data structures per value, reference, or pointer
Instance methods and static methods
Overloaded functions
Instance attributes and static attributes
Exceptions
Enumerations
Callbacks
Custom operators
STL data structures
Iterators and ranges
Smart pointers with reference counting like
std::shared_ptrInternal references with correct reference counting
C++ classes with virtual (and pure virtual) methods can be extended in Python
支持的編譯器:
Clang/LLVM (any non-ancient version with C++11 support)
GCC (any non-ancient version with C++11 support)
Microsoft Visual Studio 2015 or newer
Intel C++ compiler v15 or newer
