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 7171565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:26:22+00:00 2026-05-28T15:26:22+00:00

I’ve changed some code to convert a std::set to a boost::ptr_set . However, the

  • 0

I’ve changed some code to convert a std::set to a boost::ptr_set. However, the code doesn’t compile; the problem is that I’m assuming that the return value from a ptr_set insert is the same as a set insert (a pair<myIter, bool>). After an hour on Google I found this, and it turns out that the return value from a ptr_set insert appears to be a bool.

Is there any definitive documentation on the differences between the ptr containers and the std containers? I haven’t found anything on the boost website, but maybe I’m just being dumb…

EDIT

Ok – what was confusing me was that this code

  t.insert(s.release(s.begin()));
  p = t.insert(s.release(s.begin()));

reports no error on the first line on gcc, but reports no match for operator= on the second line, so I thought the error was in the return type. However, if you comment out the second line, the first line is then reported as an error (release doesn’t return an iterator). My confusion was compounded by the link I posted, in which ptr_container’s author states that “insert() in ptr_set<> returns bool”. However, reading on down the link it becomes obvious that the code hadn’t been finished at the time. Thanks Kerrek.

  • 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-28T15:26:23+00:00Added an answer on May 28, 2026 at 3:26 pm

    The following code works as expected, and the interface is the same as for std::set::insert():

    #include <boost/ptr_container/ptr_set.hpp>
    #include <boost/assign/ptr_list_inserter.hpp>
    #include <iostream>
    
    int main()
    {
      boost::ptr_set<int> s;
    
      {
        auto p = s.insert(new int(4));
        std::cout << "Element " << *p.first << (p.second ? " inserted" : " already existed") << std::endl;
      }
      {
        auto p = s.insert(new int(4));
        std::cout << "Element " << *p.first << (p.second ? " inserted" : " already existed") << std::endl;
      }
    
      boost::assign::ptr_insert(s)(1)(2)(3)(4);
    
      for (auto it = s.begin(), end = s.end(); it != end; ++it) { std::cout << *it << "\n"; }
    }
    

    The documentation is perhaps not the easiest to navigate, but it’s all there. You should look for the “set adapter”, though, perhaps that’s not entirely obvious.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.