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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:54:28+00:00 2026-05-19T23:54:28+00:00

currently I am trying to understand how to move an element in Boost::ptr_list to

  • 0

currently I am trying to understand how to move an element in Boost::ptr_list to the front.

I have been trying stuff like this:

boost::ptr_list<myObj> mylist;
boost::ptr_list<myObj> myiter;
// Do something useful
mylist.transfer(mylist.begin(), myiter, mylist);

This version the compiler acccepts, but my program crashes on the first call to transfer.

Another thing I tried was

mylist.push_front(mylist.release(myiter));

This the compiler rejects due to incompatible types.

What am I doing wrong? Thanks for your help.

  • 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-19T23:54:29+00:00Added an answer on May 19, 2026 at 11:54 pm

    I am assuming here you want to move the last element in the list to the front. If so here is one possible way to do it:

    struct myObj 
    {
        myObj( int i ) : m_i(i)
        {
    
        }
    
        void print() const
        {
            std::cout << "i == " << m_i << std::endl;
        }
    
    private:
    
        int m_i;
    };
    
    typedef boost::ptr_list<myObj> tMyList;
    
    void PrintList( const tMyList& list )
    {
        std::cout << "List contains: " << std::endl;
    
        tMyList::const_iterator itEnd = list.end();
        for (tMyList::const_iterator it = list.begin(); it != itEnd; ++it )
        {
            it->print();
        }
    }
    
    void test()
    {
        tMyList mylist;
    
        mylist.push_back(new myObj(1));
        mylist.push_back(new myObj(2));
        mylist.push_back(new myObj(3));
    
        PrintList(mylist);
    
        //move last element to the front
        tMyList::auto_type pBack = mylist.pop_back();
        mylist.push_front( pBack.release() );
    
        PrintList(mylist);
    }
    
    int main() 
    { 
        test();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to understand some of the fundamentals with LINQ. I have been
Been trying my best to understand this correctly. What is the difference between an
I've been evaluating HTML5 audio on iOS 4 and have been trying to understand
I'm currently trying to understand per pixel collision detection. This is the code I
I am currently trying to understand the ray tracer developed by Kevin Beason (smallpt:
Im currently trying to learn some stuff about encryption, it's algorithms and how it
I'm currently trying out db4o (the java version) and I pretty much like what
I am currently trying to figure out how to do move semantics correctly with
I'm currently trying to understand the intrinsics of iterators in various languages i.e. the
I'm currently trying to understand how to implement a 2-dimensional array of struct in

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.