我正在使用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) 我正在尝试使用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)