Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6351045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:55:36+00:00 2026-05-24T21:55:36+00:00

This is not a question about putting std::auto_ptr into std::vector. Is there some vector

  • 0

This is not a question about putting std::auto_ptr into std::vector.

Is there some vector equivalent of std::auto_ptr in std::, std::tr1:: or boost::? I use std::auto_ptr in function parameters and return values to decalre ownership semantics of these functions. But this way I can pass only single objects. As a temporary solution for vectors I have this:

std::auto_ptr<std::vector<std::tr1::shared_ptr<ClassExample> > > fx(....);

which, I suppose, by introducing boost, I will be able to change into this:

std::auto_ptr<std::vectro<boost::unique_ptr<ClassExample> > >f(...);

in order to define strict ownership passing, but it seems to be quite complicated. To simplify it, I can use

std::vector<boost::unique_ptr<ClassExample> > f(...);

as the price for deep copy of the vector is not high, but I am still curious if there is something that I can use like this:

auto_vector<ClassExample> f(...);

meaning that the function is releasing ownership of all the objects and the vector internal data array is not deeply copied.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:55:37+00:00Added an answer on May 24, 2026 at 9:55 pm

    Without any particular reason as to why you need to maintain a vector of pointers, the first solution would be to ditch all the complexity and go for the simple:

    std::vector<Type> f();
    

    Ownership of the objects is unique (the vector owns them), and while the code looks like it is copying the vector on return it will be optimized away in most cases.

    If you need the objects inside the vector to be dynamically allocated due to some other requirement (objects must be allocated through a factory, they are pointers to derived types, or they cannot move due to vector growth — code maintains references/pointers) that you are not showing then I would go for a boost::ptr_vector that will maintain ownership of the contained objects. Again, return by value:

    boost::ptr_vector<Type> f();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is NOT about race-conditions, atomicity, or why you should use locks in
No, this is not a question about generics. I have a Factory pattern with
This is a question not really about programming (is not specific to any language
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
Ok this is a general question about how to solve this issue, not to
I asked a similar question about this previously, but I did not specify that
This question is about removing sequences from an array, not duplicates in the strict
This is mostly a theoretical question I'm just very curious about. (I'm not trying
THIS QUESTION IS NOT ABOUT HOW TO SET DEFAULT VALUE OF A WIDGET Hello
I just have a question about putting a single form with multiple inputs into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.