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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:14:02+00:00 2026-06-02T11:14:02+00:00

I have a object container, list; and class Foo have a member function id()

  • 0

I have a object container, list; and class Foo have a member function id() return an integer identifier.
Now I want to use stl algorithm remove_if to remove some objects whose id is less than a value.
I don’t want to provide a function for id compare, If it is possible for me to write one line code with STL but boost to implement it.

class Foo{
public:
  unsigned id() const {return id_;}
  ...
private:
  unsigned id_
  ...
};
list<Foo> foo_list;
std::remove_if(foo_list.begin(), foo_list.end(), ???);

If STL can do this with only std::bind2nd, stl::less(), std::mem_fun_ref() or other stl functions.

  • 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-06-02T11:14:03+00:00Added an answer on June 2, 2026 at 11:14 am

    Yes, that is possible to achieve without lambdas, if you agree to change the interface of Foo a little bit.

    class Foo
      {
    public:
      Foo(unsigned id)
        : id_(id) {}
      bool is_equal(unsigned id) const
        { return id_ == id; }
    private:
      unsigned id_;
      };
    
    typedef list<Foo> FooList;
    
    FooList foo_list;
    foo_list.push_back(Foo(1));
    foo_list.push_back(Foo(2));
    
    unsigned to_remove = 1;
    foo_list.remove_if(std::bind2nd(std::mem_fun_ref(&Foo::is_equal), to_remove));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

abstract class Foo { private List<Object> container; private bool update; Foo Foo() { container
I have a container class (subclassed from list) where I have overridden the geattr
I have a Ticket class that contains a List of User objects: class Ticket
I have a class Player that contains a list of Accessory objects. There are
I have an object which is contained within a List<>, I need to remove
I have an Object X which contains a list of Objects X. I do
I have a list of objects and in each object they contain a list
I have filled List<Object1> Object 1 contain 2 fields (int id & string name)
I have a List which contains a list of objects and I want to
I have a class Foo which overrides equals() and hashCode() properly. I would like

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.