私はpythonを初めて使用します。boost pythonを見てきましたが、非常に印象的です。ただし、導入を進めると、オブジェクトのベクトルが python リスト/タプルとして返される例が見つかりません。
つまり、この例を見てみましょう。クラス X、Cont、およびそのすべての関数を公開したいと考えています。重要なビットは、X または文字列のベクトルを Python に返します
class X {};
class Cont {
.....
// how can this be exposed using boost python
const std::vector<X>& const_ref_x_vec() const { return x_vec_;}
std::vector<X> value_x_vec() const { return x_vec;}
const std::vector<std::string>& const_ref_str_vec() const { return str_vec_;}
std::vector<std::string> value_str_vec() const { return str_vec_; }
...
private:
std::vector<X> x_vec_;
std::vector<std::string> str_vec_;
};
const_ref_x_vec()、value_x_vec() などの関数を公開しようとする私自身の実りのない試みは、コンパイル エラーにつながります。
グーグルで調べたところ、値または参照でベクトルを返すことをサポートする例は見たことがありません。これはboost pythonでも可能ですか?回避策はありますか?この場合、SWIG を使用する必要がありますか?
どんな助けでも感謝します。
アバター