473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

remove_if

2
Hi,

I have a vector of pair<string, string> in my code which holds the list of tokens found in a particular file. The first string is the file name and the second is the token. The vector represents the (file, token) pair, in the order they were encountered during parsing

Now my task is to retain only the pairs corresponding to the largest token found in the current file. In case there are two or more pairs with tokens of the same length, I want to retain them in the order in which they were encountered.

Please advice on how this could be done. I want to avoid any global variables in my code that corresponds to the length of the current max length of the tokens enountered and passing that in the predicate function.

Regards,
Anubhav.
Jun 28 '07 #1
1 1814
weaknessforcats
9,208 Expert Mod 8TB
This looks like you may need a:
Expand|Select|Wrap|Line Numbers
  1. vector< vector<pair<string, string> > >  v;
  2.  
That way element v[i] is a vector of pairs. You just need to make sure that the file for this contained vector is always the same file. The tokens will then be in the order received.

You might also consider:
Expand|Select|Wrap|Line Numbers
  1. vector< priority_queue<pair<string, string> > > pv;
  2.  
This is same approach except v[i] is a priority_queue, which is sorted so you easily get the largest token. However, since it is sorted, if tokens have the same length, the order in the queue just guarantees that they are adjacant.
Jun 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: skscpp | last post by:
What's wrong with the following code? Compiler error is at the bottom. The compiler I am using is gcc version 2.95. ============================= // traits.h =============================...
4
by: CupOfWater | last post by:
Hi, I'm getting some errors using remove_if that I can not fix at all. Let me paste my code and also the error here. I went on IRC and people were mostly no help. The compiler is g++ 3.2.3. ...
5
by: Wang Tong | last post by:
I have the following code, which removes a pair (string, int) from the set. I defined a predicate that returns true if the string value matches. But I am getting compiler error on the remove_if...
1
by: Paavo K | last post by:
Hi, can anyone tell what is wrong with following code : //..Code class removeTest { public: bool operator()(map<int, string>::value_type &d) const { // Just returning false to simplify...
2
by: marco_segurini | last post by:
Hi, if I compile the following code I get the error: RemoveIf.cpp(19) : error C2914: 'remove_if' : cannot deduce template argument as function argument is ambiguous #include <algorithm>...
0
by: marco_segurini | last post by:
Hi, I am trying to solve this problem: I have a vector V1 that is not empty and a vector V2 that contains some iterator that point to V1 elements. Now I want to remove the V1 elements that V2...
2
by: Adam Hartshorne | last post by:
Hi All, I want to do the following, I have a std::vector<Patch> called say vs. Now there is a bool variable in the class called outlier, which may be access by getOutlierStatus() method. ...
3
by: Jon Rea | last post by:
Hello all, Sorry if this is long, but I wanted to be specific... Can anyone shed any light on the following errors in the context of the following example code: cullMethod1(); // compiles,...
3
by: Angus | last post by:
Hi I have a class CRequest with a function: bool IsFinished() const; I have a list of these CRequests - list<CRequestmylist. I create a function object to find if a CRequest is finished:...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.