Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Exporting wrapped functions doesn't work

オープン
#466 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp
領域
api

調査の方向性

まず、issue にあるラップされた関数の例を再現し、次に boost::python::def のエントリポイントと callable オブジェクトの処理を調べます。ラップされた add2 と add の例を、すでに直接動作しているケースと同様に正常にエクスポートできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

I find myself in need of exporting a whole lot of functions to Python which require a wrapper (the API needs locking and whatnot).

The following code probably should work (pybind11 can handle it, for the most part), but doesn't.

#include <iostream>
#include <boost/python.hpp>

template <class R, class... Args>
struct wrap
{
    using funct_type = R(*)(Args...);
    funct_type func;
    wrap(funct_type f): func(f) {};
    R operator()(Args&&... args)
    {
          std::cout << "before calling\n";
          R ret=func(std::forward<Args>(args)...);
          std::cout << "After calling\n";
          return ret;
    }
};

class bar {};
class foo : bar {
    public:
    enum xfoo { FOO=1, BAR=2, BAZ=3    };
    static int add(int a, int b, enum xfoo c) { return a+b; }
    static int add2(int a, int b) { return a+b; }
};

BOOST_PYTHON_MODULE(example)
{
    using namespace boost::python;

    // this works
    std::cout << "Result" << wrap{foo::add}(1,2, foo::xfoo::FOO) << std::endl;

    // so does this
    def("add", foo::add, "A function that adds two numbers and no enum");

    // this works with pybind11 but not boost
    def("add2", wrap{foo::add2}, "A function that adds two numbers");

    // this works with neither
    def("add", wrap{foo::add}, "A function that adds two numbers and no enum");
}
主要言語
C++
スター
537
フォーク
223
平均マージ
11時間 22分
マージ済み PR(30日)
2

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/python のほかの issue

boostorg/python の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。