简体   繁体   English

使用std :: shared_ptr <std :: vector>而不是boost :: shared_array是否有意义?

[英]Does it make sense to use std::shared_ptr<std::vector> instead of boost::shared_array?

Now I'm rewriting a part of my code to use C++11 standard. 现在我正在重写我的代码的一部分以使用C ++ 11标准。 In some places I found the following code: 在某些地方我发现了以下代码:

boost::shared_array<uint8_t> array;

Does it make to replace it with: 它是否可以替换为:

std::shared_ptr<std::vector<uint8_t>> array;

I'm trying to replace all boost's functionality that already presented in C++11 in my code. 我正在尝试替换我的代码中已经在C ++ 11中提供的所有boost功能。

I need to clarify a bit. 我需要澄清一下。 Actually I need a raw array (but with refcount, so it can be automatically deleted), no need for all those vector features. 实际上我需要一个原始数组(但使用refcount,因此可以自动删除),不需要所有这些矢量功能。 So boost::shared_array solves the problem I want without any additional cost. 因此boost :: shared_array解决了我想要的问题而无需任何额外费用。 But I'm trying to make my code uses new standard as much as possible (though many libraries from boost still not covered by the new standard). 但是我正在努力让我的代码尽可能地使用新标准(虽然许多来自boost的库仍未被新标准所涵盖)。

Thanks. 谢谢。

Given the current state of affairs in C++11 support in compilers and the laziness of people maintaing builds, I would leave that as-is now. 鉴于编译器中C ++ 11支持的当前状态以及维护构建的人员的懒惰,我现在将其保留原样。 Boost has the nice property of working virtually everywhere, including old compilers, and the change you want to make will hardly improve the code. Boost几乎可以在任何地方工作,包括旧编译器,并且您想要进行的更改很难改进代码。

This code also isn't exactly the same. 这段代码也不完全一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么使用一个与另一个:`boost::shared_array` VS `boost::shared_ptr<std::vector> `?</std::vector> - Why use one vs the other: `boost::shared_array` VS `boost::shared_ptr<std::vector>`? 我应该继续使用boost :: shared_array还是使用boost :: shared_ptr <type []> 代替? - should I continue to use boost::shared_array or use boost::shared_ptr<type []> instead? 初始化boost :: shared_ptr <std::vector<T> &gt;使用boost :: shared_ptr <std::list<T> &gt; - Initializing boost::shared_ptr<std::vector<T>> with boost::shared_ptr<std::list<T>> boost :: ptr_container和std :: vector <shared_ptr> - boost::ptr_container and std::vector<shared_ptr> 使用 BOOST shared_array 而不是 shared_ptr 的好处 - Benefits of using BOOST shared_array over shared_ptr boost :: shared_array <char> 到std :: string - boost::shared_array<char> to std::string std :: vector的std :: shared_ptr用法 - std::vector of std::shared_ptr usage 访问包含boost :: shared_ptr的std :: vector <CustomObj> -&gt; at()是否返回共享指针的副本? - Accessing std::vector containing boost::shared_ptr<CustomObj> -> does at() return a copy of shared pointer? 使用* this作为std :: shared_ptr - use *this as std::shared_ptr 在SWIG中为Python包装boost :: shared_ptr的std :: vector - Wrapping std::vector of boost::shared_ptr in SWIG for Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM