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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:38:06+00:00 2026-05-24T07:38:06+00:00

I wrote a class method using STL find_if . The code is the following:

  • 0

I wrote a class method using STL find_if. The code is the following:

void
Simulator::CommunicateEvent (pEvent e)
{
  pwEvent we (e);
  std::list<pEvent> l;

  for (uint32_t i = 0; i < m_simulatorObjects.size (); i++)
  {
    l = m_simulatorObjects[i]->ProcessEvent (we);
    // no action needed if list is empty
    if (l.empty ())
      continue;
    // sorting needed if list comprises 2+ events
    if (l.size () != 1)
      l.sort (Event::Compare);

    std::list<pEvent>::iterator it = m_eventList.begin ();
    std::list<pEvent>::iterator jt;
    for (std::list<pEvent>::iterator returnedElementIt = l.begin ();
         returnedElementIt != l.end ();
         returnedElementIt++)
    {
      // loop through the array until you find an element whose time is just
      // greater than the time of the element we want to insert
      Simulator::m_eventTime = (*returnedElementIt)->GetTime ();
      jt = find_if (it,
                    m_eventList.end (),
                    IsJustGreater);
      m_eventList.insert (jt, *returnedElementIt);
      it = jt;
    }
  }
}

Unfortunately, I later discovered that the machine that will run the code is equipped with the libstdc++ library version 4.1.1-21, which apparently is lacking find_if. Needless to say, I cannot upgrade the library, nor can I ask someone to do it.

When compiling, the error I get is:

simulator.cc: In member function ‘void sim::Simulator::CommunicateEvent(sim::pEvent)’:
simulator.cc:168: error: no matching function for call to ‘find_if(std::_List_iterator<boost::shared_ptr<sim::Event> >&, std::_List_iterator<boost::shared_ptr<sim::Event> >, sim::Simulator::<anonymous struct>&)’
simulator.cc: In static member function ‘static void sim::Simulator::InsertEvent(sim::pEvent)’:
simulator.cc:191: error: no matching function for call to ‘find_if(std::_List_iterator<boost::shared_ptr<sim::Event> >&, std::_List_iterator<boost::shared_ptr<sim::Event> >, sim::Simulator::<anonymous struct>&)’
make: *** [simulator.o] Error 1

How can I solve the problem?

I thought I could define a find_if function as described here. However, I have some concerns:

  1. What about performance? The function that makes use of find_if needs to be as efficient as possible.
  2. How can I do conditional compilation? I couldn’t find a macro telling the version of the libstdc++ installed.

What are your thoughts about it?
TIA,
Jir

References

Source files: simulator.h and simulator.cc

Solution

Defined IsJustGreater outside the Simulator class and declared IsJustGreater_s friend of Simulator:

struct IsJustGreater_s : public std::unary_function<const pEvent, bool> {
  inline bool operator() (const pEvent e1) {return (e1->GetTime () > Simulator::m_eventTime);}
} IsJustGreater;

Called IsJustGreater in find_if this way:
jt = find_if (it, m_eventList.end (), sim::IsJustGreater);

  • 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-24T07:38:07+00:00Added an answer on May 24, 2026 at 7:38 am

    From the error, it appears that you’re attempting to use an anonymous type as the argument. I do not believe anonymous types are allowed to be template arguments.

    From the error, I believe you have something like this:

    class Simulator {
        struct {
           bool operator(const pEvent& p) { ... } ;
        } IsJustGreater;
    }
    

    what you want is to give it a name and then change the find_if to instantiate the class (see below)

    class Simulator {
        // class is now an inner named-class
        struct IsJustGreater {
            bool operator(const pEvent& p) { ... } ;
        };
    }
    
    
    // This is how you use the class
    jt = std::find_if(it, m_eventList.end(), IsJustGreater() );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need mock some class with final method using mockito. I have wrote something
I've wrote a java code and compiled it. (foo1.6.class) According to my search, my
I was using newInstance() in a sort-of performance-critical area of my code. The method
I wrote a setter and getter method following Apple's conventions and noticed that despite
I wrote the following class in javascript function main() { this.area ; this.$= function(target)
I am using a System.Collections.Generic , which contains instances of a class I wrote.
Hie I am using GAE jdoql and wrote query like: Query query = pm.newQuery(BloodDonor.class);
I created c++ dll (using mingw) from code I wrote on linux (gcc), but
I wrote a valitor class with a fair amount of regex in there. Using
I wrote a method(getDirTree1) that makes listing all directories from the root, using the

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.