I'm trying to use the set<my_class>::insert( my_class const & )
method, but have run into some problems. It seems like I'm seeing it
insert an object when a similar object is already in the set.
After calling insert(), I see the .second of the return value set to
"true", meaning it was inserted. The size() of the set increases by
1, but the count() of the object I insert doesn't change (it was 1, it
is still 1). I do a quick check and see that my new object is not
less than the one already in the set, and the one already in the set
is not less than the new object.
Does that make any sense? I can't really post all the code, but I
could post some pseudocode if that helps...
I tried reproducing outside the program but didn't have much luck.
Does anybody have a suggestion for something in general I might be
doing wrong? My operator< is defined and looks fine to me. I'm using
GCC 3.4.6.
Thanks!
Rob 5 2720
Rob wrote:
I'm trying to use the set<my_class>::insert( my_class const & )
method, but have run into some problems. It seems like I'm seeing it
insert an object when a similar object is already in the set.
After calling insert(), I see the .second of the return value set to
"true", meaning it was inserted. The size() of the set increases by
1, but the count() of the object I insert doesn't change (it was 1, it
is still 1). I do a quick check and see that my new object is not
less than the one already in the set, and the one already in the set
is not less than the new object.
Does that make any sense? I can't really post all the code, but I
could post some pseudocode if that helps...
I tried reproducing outside the program but didn't have much luck.
Does anybody have a suggestion for something in general I might be
doing wrong? My operator< is defined and looks fine to me. I'm using
GCC 3.4.6.
Let's see some code, especially the definition of 'my_class' and its
operator<. While we're lookint at it, read up on "strict weak ordering".
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Mar 7, 9:15 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Rob wrote:
I'm trying to use the set<my_class>::insert( my_class const & )
method, but have run into some problems. It seems like I'm seeing it
insert an object when a similar object is already in the set.
After calling insert(), I see the .second of the return value set to
"true", meaning it was inserted. The size() of the set increases by
1, but the count() of the object I insert doesn't change (it was 1, it
is still 1). I do a quick check and see that my new object is not
less than the one already in the set, and the one already in the set
is not less than the new object.
Does that make any sense? I can't really post all the code, but I
could post some pseudocode if that helps...
I tried reproducing outside the program but didn't have much luck.
Does anybody have a suggestion for something in general I might be
doing wrong? My operator< is defined and looks fine to me. I'm using
GCC 3.4.6.
Let's see some code, especially the definition of 'my_class' and its
operator<. While we're lookint at it, read up on "strict weak ordering".
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I'm very sorry for not being able to post the actual code - it's not
public and all that...
struct my_class {
std::string mString1;
std::string mString2;
double mDouble;
std::vector<unsigned charmVector1;
std::vector<unsigned charmVector2;
my_class();
my_class( string,string,double );
my_class( string, string, time, std::vector<unsigned char);
my_class( string, std::vector<unsigned char);
my_class( my_class const & other );
bool operator< ( my_class const & other ) const;
bool operator== ( my_class const & other ) const;
};
bool my_class::operator < ( my_class const & other ) const
{
return ( mString1 < other.mString1
|| ( !(other.mString1 < mString1)
&& mString2 < other.mString2 )
|| ( !(other.mString2 < mString2)
&& mDouble < other.mDouble )
|| ( !(other.mDouble < mDouble)
&& mVector1 < other.mVector1 )
|| ( !(other.mVector1 < mVector1)
&& mVector2 < other.mVector2 ) );
}
Some notes/thoughts:
- Sorry for formatting; I'm using google groups which doesn't have
fixed-width fonts
- I removed most "const &" from the constructor declarations
- The two byte vectors are empty for the situation I'm describing
- The two strings are equal as well
- The two doubles appear to be equal (with std::fixed), and I believe
they are truly equal
- The operator< returns false either way - I take it to mean the
objects are equivalent
- The fact that count(obj) returns 1 before the insert makes me very
surprised that the
object is inserted!
Thanks for your help!
Rob
Rob wrote:
On Mar 7, 9:15 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Rob wrote:
>>I'm trying to use the set<my_class>::insert( my_class const & ) method, but have run into some problems. It seems like I'm seeing it insert an object when a similar object is already in the set.
>>After calling insert(), I see the .second of the return value set to "true", meaning it was inserted. The size() of the set increases by 1, but the count() of the object I insert doesn't change (it was 1, it is still 1). I do a quick check and see that my new object is not less than the one already in the set, and the one already in the set is not less than the new object.
>>Does that make any sense? I can't really post all the code, but I could post some pseudocode if that helps...
>>I tried reproducing outside the program but didn't have much luck.
>>Does anybody have a suggestion for something in general I might be doing wrong? My operator< is defined and looks fine to me. I'm using GCC 3.4.6.
Let's see some code, especially the definition of 'my_class' and its operator<. While we're lookint at it, read up on "strict weak ordering".
V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
I'm very sorry for not being able to post the actual code - it's not
public and all that...
[..code..]
Some notes/thoughts:
- Sorry for formatting; I'm using google groups which doesn't have
fixed-width fonts
- I removed most "const &" from the constructor declarations
- The two byte vectors are empty for the situation I'm describing
- The two strings are equal as well
- The two doubles appear to be equal (with std::fixed), and I believe
they are truly equal
- The operator< returns false either way - I take it to mean the
objects are equivalent
- The fact that count(obj) returns 1 before the insert makes me very
surprised that the
object is inserted!
OK, you're right about equivalency requirement. If comp(a,b) == false
and comp(b,a) == false, they are equivalent. That leaves only the
procedure that takes place upon insertion. It should only insert if
there is no equivalent element in the set. Unless you can come up with
the code we can copy-paste-compile-run, the only speculation remains
here is that either your library is at fault (insertion does not check
equivalency [correctly]), or there is another error elsewhere in your
program.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Mar 7, 10:45 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Rob wrote:
On Mar 7, 9:15 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Rob wrote: I'm trying to use the set<my_class>::insert( my_class const & ) method, but have run into some problems. It seems like I'm seeing it insert an object when a similar object is already in the set.
>After calling insert(), I see the .second of the return value set to "true", meaning it was inserted. The size() of the set increases by 1, but the count() of the object I insert doesn't change (it was 1, it is still 1). I do a quick check and see that my new object is not less than the one already in the set, and the one already in the set is not less than the new object.
>Does that make any sense? I can't really post all the code, but I could post some pseudocode if that helps...
>I tried reproducing outside the program but didn't have much luck.
>Does anybody have a suggestion for something in general I might be doing wrong? My operator< is defined and looks fine to me. I'm using GCC 3.4.6.
Let's see some code, especially the definition of 'my_class' and its
operator<. While we're lookint at it, read up on "strict weak
ordering".
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I'm very sorry for not being able to post the actual code - it's not
public and all that...
[..code..]
Some notes/thoughts:
- Sorry for formatting; I'm using google groups which doesn't have
fixed-width fonts
- I removed most "const &" from the constructor declarations
- The two byte vectors are empty for the situation I'm describing
- The two strings are equal as well
- The two doubles appear to be equal (with std::fixed), and I believe
they are truly equal
- The operator< returns false either way - I take it to mean the
objects are equivalent
- The fact that count(obj) returns 1 before the insert makes me very
surprised that the
object is inserted!
OK, you're right about equivalency requirement. If comp(a,b) == false
and comp(b,a) == false, they are equivalent. That leaves only the
procedure that takes place upon insertion. It should only insert if
there is no equivalent element in the set. Unless you can come up with
the code we can copy-paste-compile-run, the only speculation remains
here is that either your library is at fault (insertion does not check
equivalency [correctly]), or there is another error elsewhere in your
program.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Well, I tried to extract just the classes involved, and went to some
effort to construct my objects the same way, but I just couldn't
reproduce it outside the original code. So I set up the workaround to
check count(obj) before calling insert(), which seems to work.
Thanks for your help!
Rob
>
Well, I tried to extract just the classes involved, and went to some
effort to construct my objects the same way, but I just couldn't
reproduce it outside the original code. So I set up the workaround to
check count(obj) before calling insert(), which seems to work.
It's likely that your original code has some subtle bug, but if it
'seems to work' who am I to quibble.
Usually in trying to get a handle on this kind of issue, it's better to
start removing code from the bugged program, instead of trying to build
upto the problem code from scratch.
Thanks for your help!
Rob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Xenos |
last post by:
I have elements of vector I need to add to a set. Can I just do (ignoring
namespace):
copy(v.begin(), v.end(), inserter(s, s.end()));
Where, v is a vector and s is a set, and both have the...
|
by: Mark P |
last post by:
Some time ago I posted here about inserting into a set with a hint:
...
|
by: jimmy |
last post by:
Hi,
I am getting a Fatal signal with std::set::insert(). I'm really not
sure what to
try next:
Here is my code:
std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout <<...
|
by: Johannes A. Brunner |
last post by:
Got a simple problem.
I code some site and because Im a freak I made my own session-handling.
When a user open up my site it will check if there is a ssid in the url
if not generate one. this will...
|
by: Marcus Kwok |
last post by:
I am not sure if this is something that is covered by the Standard, or
if it's an implementation detail of my Standard Library.
I am reading in a large amount of data into a std::set. There is...
| |
by: Mark Olbert |
last post by:
I am struggling with trying to retrieve the value of an autoincrement identity field after a DetailsView Insert operation. The
DetailsView is bound to an SqlDataSource control.
So far as I can...
|
by: zensunni |
last post by:
I like to use this method when inserting into a database:
Set Insert = Server.CreateObject("ADODB.Recordset")
Insert.Open "test", objConn, 1, 3, 2
Insert.AddNew
Insert("FIRSTNAME") = "Joe"...
|
by: puzzlecracker |
last post by:
I meant something else entirely. I was refering to algorithms, such as
find_if where passed predicate, which implemented operator () for
comparison. I assume set uses operator == to locate elements...
|
by: Olumide |
last post by:
Hello,
I've got this nice inner class that I'm holds a set of "FrontPoint"
objects as shown below. Unfortunately, the find and insert methods
trigger massive C2784 errors. Would someone please...
|
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,...
|
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...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |