草庐IT

c++ - 使用 std::vector< std::shared_ptr<const T>> 是反模式吗?

很长一段时间我都在使用std::vector和std::shared_ptr手牵手。最近开始使用std::shared_ptr每当需要指向const对象的指针时。没关系,因为std::shared_ptr可以转换为std::shared_ptr然后他们共享相同的引用计数器,一切都感觉很自然。但是当我尝试使用std::vector>等结构时我遇到了麻烦。为简化起见,我将表示这两种结构:templateusingSharedPtrVector=std::vector>;templateusingSharedConstPtrVector=std::vector>;问题是虽然SharedPtr

c++ - 什么时候需要使用 std::ref ?

考虑:std::tuplefunc(constA&a){returnstd::make_tuple(0,std::ref(a));}std::ref是编写正确且可移植的代码所必需的吗?(没有它也可以编译)背景:如果我删除std::ref我的代码构建良好,没有任何警告(g++-4.6-Wall),但不能正确运行。如果感兴趣,A的定义:structA{std::arrayvec;typedefinttype_t;templateA&operator=(conststd::pair,std::tuple>&e){for(inti=0;i 最佳答案

c++ - 什么时候需要使用 std::ref ?

考虑:std::tuplefunc(constA&a){returnstd::make_tuple(0,std::ref(a));}std::ref是编写正确且可移植的代码所必需的吗?(没有它也可以编译)背景:如果我删除std::ref我的代码构建良好,没有任何警告(g++-4.6-Wall),但不能正确运行。如果感兴趣,A的定义:structA{std::arrayvec;typedefinttype_t;templateA&operator=(conststd::pair,std::tuple>&e){for(inti=0;i 最佳答案

c++ - 带 malloc 和 free 的 shared_ptr

我在包含c和cpp的大型应用程序中工作。所有文件都保存为cpp扩展名,但代码是用c-style编写的。我的意思是它是定义结构而不是通过malloc和realloc和calloc分配内存的类。最近他们已经安装了boost库所以我打算在我现有的代码库中使用所以我有一些以下问题。我可以将std::shared_ptr与malloc和free一起使用吗?如果是,谁能指出我的示例代码库?如果我在我的应用程序中创建std::shared_ptr并将此指针传递给另一个使用malloc或calloc的函数,它会影响任何功能吗?或者换句话说:对于以下代码,如何使用std::shared_ptr实现类似的

c++ - 带 malloc 和 free 的 shared_ptr

我在包含c和cpp的大型应用程序中工作。所有文件都保存为cpp扩展名,但代码是用c-style编写的。我的意思是它是定义结构而不是通过malloc和realloc和calloc分配内存的类。最近他们已经安装了boost库所以我打算在我现有的代码库中使用所以我有一些以下问题。我可以将std::shared_ptr与malloc和free一起使用吗?如果是,谁能指出我的示例代码库?如果我在我的应用程序中创建std::shared_ptr并将此指针传递给另一个使用malloc或calloc的函数,它会影响任何功能吗?或者换句话说:对于以下代码,如何使用std::shared_ptr实现类似的

c++ - 在 std::move() 之后 unique_ptr 会发生什么?

这段代码就是我想做的:Tony&Movie::addTony(){Tony*newTony=newTony;std::unique_ptrtony(newTony);attachActor(std::move(tony));return*newTony;}我想知道我是否可以这样做:Tony&Movie::addTony(){std::unique_ptrtony(newTony);attachActor(std::move(tony));return*tony.get();}但是*tony.get()会是同一个指针还是null?我知道我可以验证,但它的标准做法是什么?

c++ - 在 std::move() 之后 unique_ptr 会发生什么?

这段代码就是我想做的:Tony&Movie::addTony(){Tony*newTony=newTony;std::unique_ptrtony(newTony);attachActor(std::move(tony));return*newTony;}我想知道我是否可以这样做:Tony&Movie::addTony(){std::unique_ptrtony(newTony);attachActor(std::move(tony));return*tony.get();}但是*tony.get()会是同一个指针还是null?我知道我可以验证,但它的标准做法是什么?

c++ - 为什么 shared_ptr<T>::use_count() 返回 long 而不是 unsigned 类型?

shared_ptr观察者20.8.2.2.5C++14最终草案(n4296)longuse_count()constnoexcept;Returns:thenumberofshared_ptrobjects,*thisincluded,thatshareownershipwith*this,or0when*thisisempty.[Note:use_count()isnotnecessarilyefficient.—endnote] 最佳答案 根据这个页面http://www.open-std.org/jtc1/sc22/wg21

c++ - 为什么 shared_ptr<T>::use_count() 返回 long 而不是 unsigned 类型?

shared_ptr观察者20.8.2.2.5C++14最终草案(n4296)longuse_count()constnoexcept;Returns:thenumberofshared_ptrobjects,*thisincluded,thatshareownershipwith*this,or0when*thisisempty.[Note:use_count()isnotnecessarilyefficient.—endnote] 最佳答案 根据这个页面http://www.open-std.org/jtc1/sc22/wg21

python - cqlsh连接错误: 'ref() does not take keyword arguments'

我已经尝试了thispost中的所有措施和Cassandradoc.我已经尝试运行所有版本的Cassandra,包括来自tarball和Debian包的最新版本3.7,但是当我执行cqlsh时,我不断收到错误。错误:Connectionerror:('Unabletoconnecttoanyservers',{'127.0.0.1':TypeError('ref()doesnottakekeywordarguments',)})在我将LinuxMint从17.3升级到18之前,我运行Cassandra没有问题。我相信我安装了所有必要的包,例如java8和python2.7.12。我认为