473,507 Members | 12,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

std::remove_if errors!

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. Thanks in
advance.

/usr/include/c++/3.2.3/bits/stl_algo.h: In function `_OutputIter
std::remove_copy_if(_InputIter, _InputIter, _OutputIter,
_Predicate) [with
_InputIter = std::_Rb_tree_iterator<std::pair<Algo489::node_t,
Algo489::node_t>, const std::pair<Algo489::node_t,
Algo489::node_t>&, const
std::pair<Algo489::node_t, Algo489::node_t>*>, _OutputIter =
std::_Rb_tree_iterator<std::pair<Algo489::node_t, Algo489::node_t>,
const
std::pair<Algo489::node_t, Algo489::node_t>&, const
std::pair<Algo489::node_t, Algo489::node_t>*>, _Predicate =
Algo489::Graph::equal_edge_cmp]':
/usr/include/c++/3.2.3/bits/stl_algo.h:1085: instantiated from
`_ForwardIter std::remove_if(_ForwardIter, _ForwardIter, _Predicate)
[with _ForwardIter = std::_Rb_tree_iterator<std::pair<Algo489::node_t,
Algo489::node_t>, const std::pair<Algo489::node_t, Algo489::node_t>&,
const std::pair<Algo489::node_t, Algo489::node_t>*>, _Predicate =
Algo489::Graph::equal_edge_cmp]'
algo.h:116: instantiated from here
/usr/include/c++/3.2.3/bits/stl_algo.h:1017: passing `const
std::pair<Algo489::node_t, Algo489::node_t>' as `this' argument of
`
std::pair<Algo489::node_t, Algo489::node_t>&
std::pair<Algo489::node_t,
Algo489::node_t>::operator=(const std::pair<Algo489::node_t,
Algo489::node_t>&)' discards qualifiers

// Header
#ifndef __ALGO489__H_
#define __ALGO489__H_
#include <netinet/in.h>
#include <sys/types.h>
#include <iostream>
#include <iterator>
#include <vector>
#include <functional>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
namespace Algo489 {
struct node_t {
node_t(){}
node_t(std::string ip, u_short port, char type):ip_(ip),
port_(port), type_(type) {}
std::string ip_;
u_short port_;
char type_;
};
bool operator==(const node_t& lhs, const node_t& rhs);
struct Graph {
typedef std::pair<node_t, node_t> edge_t;
struct less_node_cmp : public std::binary_function<node_t, node_t,
bool> {
bool operator() (const node_t& f, const node_t& s) const
{
if(f==s)
return false;
else {
return strcmp(f.ip_.c_str(), s.ip_.c_str());
}
}
};
struct equal_edge_cmp {
equal_edge_cmp(const edge_t& e) : edge(e) {}
bool operator() (const edge_t& e) const
{
return ((e.first == edge.first && e.second == edge.second) ||
(e.first == edge.second && e.second == edge.first));
}
edge_t edge;
};
struct less_edge_cmp : public std::binary_function<node_t, node_t,
bool> {
bool operator() (const edge_t& f, const edge_t& s) const
{
bool lessthan;
equal_edge_cmp e(f);
if(e(s)) {
return false;
}
else {
return strcmp(f.first.ip_.c_str(), s.first.ip_.c_str());
}
}
};
struct print_node {
void operator() (const node_t& e) const
{
std::cout << e.ip_ << " " << e.port_ << " " << e.type_ <<
std::endl;
}
};
struct print_conn {
void operator() (const edge_t& e) const
{
std::cout << e.first.ip_ << " " << e.first.port_ << " " <<
e.first.type_;
std::cout << " connected to: ";
std::cout << e.second.ip_ << " " << e.second.port_ << " " <<
e.second.type_;
std::cout << std::endl;
}
};
typedef std::set<node_t, less_node_cmp> nodes_t;
typedef std::set<edge_t, less_edge_cmp> vertices_t;
// functions
node_t addentry(const node_t& e)
{
return *nodes_.insert(e).first;
}
virtual bool rmentry(const node_t& e)
{
for(Graph::nodes_t::iterator i = nodes_.begin(); i != nodes_.end();
++i) {
if(*i == e) {
print_node p;
std::cout << "removing node: "; p(*i);
nodes_.erase(i);
return true;
}
}
return false;
}
// remove the links that contain that node
/*
Graph::vertices_t::iterator i = links_.begin();
while(i != links_.end()) {
Graph::edge_t tmp = *i++;
Graph::disconnect(tmp.first, e);
Graph::disconnect(tmp.second, e);
}
*/
virtual bool connect(const node_t& f, const node_t& s)
{
bool found1=false, found2=false;
for(Graph::nodes_t::iterator i = nodes_.begin(); i != nodes_.end();
++i) {
if(*i == f) found1=true;
if(*i == s) found2=true;
if(found1 && found2) {
print_node p;
links_.insert(std::make_pair(f,s));
return true;
}
}
std::cout << "one or more nodes are not found\n";
return false;
}
virtual bool disconnect(const node_t& f, const node_t& s)
{
edge_t tmp = std::make_pair(f,s);
vertices_t::iterator end = std::remove_if(links_.begin(),
links_.end(), equal_edge_cmp(tmp));
if(end == links_.end())
return false;
links_.erase(end, links_.end());
return true;
}
virtual void print() const
{
for_each(nodes_.begin(), nodes_.end(), print_node());
std::cout << "************************************************* *******************************\n";
for_each(links_.begin(), links_.end(), print_conn());
std::cout << "************************************************* *******************************\n";
}
protected:
nodes_t nodes_;
vertices_t links_;
};
void algotest();
}
#endif


//CPP
#include "algo.h"
namespace Algo489 {
bool operator==(const node_t& lhs, const node_t& rhs)
{
return !strcmp(lhs.ip_.c_str(), rhs.ip_.c_str()) && lhs.port_ ==
rhs.port_ && lhs.type_ == rhs.type_;
}
void algotest()
{
Graph db;
std::vector<node_t> incoming;
incoming.push_back(node_t("141.213.12.4", 21448, 'r'));
incoming.push_back(node_t("141.212.12.4", 2447, 'h'));
incoming.push_back(node_t("141.211.12.4", 1448, 'r'));
incoming.push_back(node_t("141.210.12.4", 148, 'h'));
incoming.push_back(node_t("141.209.12.4", 21448, 'h'));
incoming.push_back(node_t("141.208.12.4", 1445, 'r'));
incoming.push_back(node_t("141.207.12.4", 21444, 'h'));
incoming.push_back(node_t("141.206.12.4", 1445, 'h'));
incoming.push_back(node_t("141.205.12.4", 2445, 'r'));
incoming.push_back(node_t("141.204.12.4", 438, 'r'));
incoming.push_back(node_t("141.203.12.4", 21449, 'r'));
for(std::vector<node_t>::iterator i = incoming.begin();
i!=incoming.end(); ++i) {
db.addentry(*i);
}
db.print();
std::cout << "**********************************************\n" ;
db.connect(
node_t("141.203.12.4", 21449, 'r'),
node_t("121.203.12.4", 21449, 'r')
);
db.connect(
incoming[0],
incoming[1]
);
db.connect(
incoming[1],
incoming[0]
);
db.connect(
incoming[0],
incoming[1]
);
db.connect(
incoming[2],
incoming[4]
);
db.connect(
incoming[6],
incoming[7]
);
db.print();
db.disconnect(
incoming[1],
incoming[0]
);
db.print();
//db.connect(e2, e);
db.rmentry(incoming[0]);
std::cout << "after remove" << std::endl;
db.print();
}
}
Jul 19 '05 #1
4 5547
"CupOfWater" <as*******@hotmail.com> wrote in message
news:e0**************************@posting.google.c om...
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.
That's a good start, but it helps if you give some clues, like
describing where you suspect the error is based on what
you have tried and what you have looked at.
I went on IRC and people were mostly no help.
Probably because nobody wants to wade through hundreds
of lines of someone else's code.
The compiler is g++ 3.2.3.
[...]


The first thing you can do is upgrade to 3.3.x. If you are
still having problems, try again.

Dave

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
Jul 19 '05 #2
CupOfWater wrote in news:e0**************************@posting.google.c om:
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. Thanks in
advance.


std::remove_if isn't the right way to remove from a std::set<>, the
algorithm is designed for sequences such as std::vector, deque and list.

Create your own set_remove_if function use std::find_if() to find the
elements you want to erase then call your_set.erase( iterator ) to
remove them.

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #3
as*******@hotmail.com (CupOfWater) wrote in message news:<e0**************************@posting.google. com>...
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. Thanks in
advance.


There's too much code for me to wade through, you should try to find
the simplest test case possible that reproduces the bug (often in the
process of trying to do so, you will find the source of the bug).

The first thing that comes to mind here is that you're trying to use
remove_if on a std::set. There is (was) a problem with this, and I
believe there was a fix in later versions of the g++ standard library
implementation.

--
Stephen M. Webb
Jul 19 '05 #4
In article <e0**************************@posting.google.com >,
as*******@hotmail.com says...
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. Thanks in
advance.


First, try to reduce the code to the minimum possible that demonstrates
the problem. In the process, be _sure_ you eliminate the use of non-
standard headers (e.g. netinet/in.h).

In that process, there's a pretty fair chance that you'll figure out
what's wrong on your own, but if you're still having the same problem,
post the what you get, and there's a much better chance of somebody
figuring out the problem.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1844
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
5167
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
2435
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
1482
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...
6
7991
by: Jason Heyes | last post by:
What is a good way of removing elements from std::vector so that the elements removed satisfy a predicate and end up stored in another std::vector. It seems as though the algorithm std::remove_if...
15
3802
by: Andrew Maclean | last post by:
I guess this problem can be distilled down to: How do I search through a string, find the first matching substring, replace it, and continue through the string doing this. Can replace_if() be used...
2
1943
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. ...
16
3569
by: Frank Neuhaus | last post by:
Hi I have some std list, I'd like to traverse. During the traversal, I want to conditionally delete some objects. My code for that is like this right now: for (std::list<myStruct>::iterator...
5
8636
by: Christopher | last post by:
The situation is that a std::list<std::set<std::string is being iterated through. Upon certain criteria some sets become empty. I need to remove the empty sets from the list. Is it safe to...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.