小编man*_*ake的帖子

Boost.Python - 如何通过引用返回?

我正在使用Boost.Python从C++类创建Python模块.我遇到了引用的问题.

Condider以下情况我有一个类Foo,带有重载的get方法,可以通过值或引用返回.

一旦我输入了签名,指定应该使用值返回很容易.但我认为应该可以通过使用a返回引用 return_value_policy.但是,使用看似合适的东西(doc); return_value_policy<reference_existing_object>似乎没有用.

我误解了它的作用吗?

struct Foo {
    Foo(float x) { _x = x; }
    float& get() { return _x; }
    float  get() const { return _x; }
private:
    float _x;
};

// Wrapper code
BOOST_PYTHON_MODULE(my_module)
{
    using namespace boost::python;
    typedef float (Foo::*get_by_value)() const;
    typedef float& (Foo::*get_by_ref)();

    class_<Foo>("Foo", init<float>())
        .def("get", get_by_value(&Foo::get))
        .def("get_ref", get_by_ref(&Foo::get),
            return_value_policy<reference_existing_object>())//Doesn't work
        ;
}
Run Code Online (Sandbox Code Playgroud)

注意:我知道在没有生命周期管理的情况下引用现有对象可能会很危险.

更新:
看起来它适用于对象但不适用于基本数据类型.
拿这个修改过的例子:

struct Foo {
    Foo(float x) { _x = x; }
    float& get() { return …
Run Code Online (Sandbox Code Playgroud)

python boost boost-python

11
推荐指数
1
解决办法
1万
查看次数

`git clone` over"dumb"http协议失败,找不到'repository'

我的问题

我正在尝试使用dumb http协议在我们公司的Intranet服务器上共享一个git repo ,它只需要文件访问,但它失败了

fatal: repository 'http://my-url/repo.git' not found
Run Code Online (Sandbox Code Playgroud)

但是,粘贴在Firefox相同的链接给我的指标到裸露的回购有branches/,config,description,HEAD等所有的目录和文件读取.事实上,如果我使用wget递归地下载整个事物,我可以git clone在本地下载,所以所有必需的文件似乎都可以访问而没有问题.

$ wget -r --no-parent --reject "index.html*" http://my-url/repo.git
$ git clone repo.git test
Cloning into 'test'...
done.
Run Code Online (Sandbox Code Playgroud)

继续调试我尝试使用GIT_CURL_VERBOSE和详细输出GIT_TRACE:

$ GIT_CURL_VERBOSE=1 GIT_TRACE=1 git clone http://my-url/repo.git test
trace: built-in: git 'clone' 'http://my-url/repo.git' 'test'
Cloning into 'test'...
trace: run_command: 'git-remote-http' 'origin' 'http://my-url/repo.git'
* Couldn't find host my-url in the .netrc file; using defaults
* …
Run Code Online (Sandbox Code Playgroud)

git

7
推荐指数
2
解决办法
2320
查看次数

标签 统计

boost ×1

boost-python ×1

git ×1

python ×1