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

  • SEARCH
  • Home
  • 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 976639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:46:45+00:00 2026-05-16T03:46:45+00:00

EDIT: I should’ve mentioned, I was looking at the documentation for Boost’s ptr_sequence_adapter and

  • 0

EDIT: I should’ve mentioned, I was looking at the documentation for Boost’s ptr_sequence_adapter and it claims that their adapter for template< class U > void push_back( ::std::auto_ptr<U> x ); is equivalent to doing vec.push_back(autoPtr.release()); and also provides the strong exception guarantee. And then I realized I was confusing their description of the effect of the implementation for what the implementation actually was, and so this question is semi-nonsensical. I’m just leaving it here for posterity.

To me, it seems the call to std::auto_ptr<t> would succeed, and then the call to std::vector<t*>::push_back could throw an exception, and the pointer would be leaked.

It seems like you’d have to do this instead:

vec.push_back(0); //Attempts to allocate space in vector, could throw bad_alloc
vec.back() = autoPtr.release(); //Provides nothrow
  • 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-16T03:46:46+00:00Added an answer on May 16, 2026 at 3:46 am

    This is specifically a feature of the Boost pointer containers library.

    The base push_back member function is defined as:

    void push_back( value_type x )  // strong               
    {
        this->enforce_null_policy( x, "Null pointer in 'push_back()'" );
    
        auto_type ptr( x );           // notrow
        this->base().push_back( x );  // strong, commit
        ptr.release();                // nothrow
    }
    

    (from the ptr_sequence_adapter.hpp header)

    So, the push_back function itself takes ownership of the pointer and if reallocation fails, it takes responsibility for deleting the pointer.

    The push_back overload that takes an auto_ptr is defined in terms of the base push_back function:

    template< class U >
    void push_back( std::auto_ptr<U> x )
    {
        push_back( x.release() );
    }
    

    The pointer is released before the call to the base push_back, which is okay because the base push_back function has a strong guarantee that it will delete the pointer if an exception is thrown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: When should and shouldn't you break away from OOP for speed/performance? might be
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
[Edit] And, I should add, most elegantly? I guess (but not sure how) I
EDIT: solved it, turns out I should use %c not %s because foodSelect and
EDIT: My main code no longer works, should this function work? <script type=text/javascript src=jquery-1.7.2.js></script>
within my App it should be forbidden to edit (customize) the TabBar. This means
EDIT: I was an idiot. I simply had an image that was vertically long,
EDIT: See my answer below--> I am wanting to have a view that when
I have a subroutine in Perl that should be indented like this: sub GetFiles
---added (edit) -- should you do validation at the service layer, even if you

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.