6

Now I'm rewriting a part of my code to use C++11 standard. 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.

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. So boost::shared_array solves the problem I want without any additional cost. 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).

Thanks.

1
  • Well, you could get rid of a boost dependency in that case. For the rest, it's functionally equivalent at a high level. Commented May 13, 2013 at 15:59

1 Answer 1

4

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. Boost has the nice property of working virtually everywhere, including old compilers, and the change you want to make will hardly improve the code.

This code also isn't exactly the same.

Sign up to request clarification or add additional context in comments.

14 Comments

@maverik: C++11 has shared_ptr<T[]> and unique_ptr<T[]> specializations, which I guess fullfill exactly that purpose.
@rubenvb: C++11 does not have a shared_ptr<T[]> specialization, you have to provide your own custom deleter to make shared_ptr work with arrays.
@AndyProwl Wait, what? That's absolutely not how I remember it. Valgrind would have told me differently if it were true
Andy is right here, you have to supply proper deleter to shared_ptr for it to work correctly. If it worked for you @sehe, that might be just your standard library playing nice, but the standard doesn't have it.
@sehe: Indeed, the specialization for std::unique_ptr<> is defined in the Standard. Btw here is the proposal to have shared_ptr<T[]> as well
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.