proper erasing from ptr_vector

I have ptr_vector<A> lst; When I need to erase element from this container - should I just do A* el; iterator it = std::find (lst.begin(), lst.end(), el); lst.erase(it); or A* el; iterator it = std::find (lst.begin(), lst.end(), el); delete lst.erase(el);

AMDG Archie14 wrote:
ptr_vector<A> lst;
When I need to erase element from this container - should I just do A* el; iterator it = std::find (lst.begin(), lst.end(), el); lst.erase(it);
or
A* el; iterator it = std::find (lst.begin(), lst.end(), el); delete lst.erase(el);
erase deletes the element and returns an iterator to the next element. In Christ, Steven Watanabe

Steven Watanabe skrev:
AMDG
Archie14 wrote:
ptr_vector<A> lst;
When I need to erase element from this container - should I just do A* el; iterator it = std::find (lst.begin(), lst.end(), el); lst.erase(it);
Replace "A* el" with "A el". Objects are compared not by their pointer value, but by the paointee. -Thorsten

I am working on a
cmoney_t class using decNumber package (ICU license).
IBM has decNumber++ class but that one is for commercial use, so I
cannot use it.
I am using this example
http://www.boost.org/doc/libs/1_38_0/libs/utility/operators.htm#example
but cannot understand
why object is returned from those operators and not an object reference
second, I do not quite understand, what exactly is a set of
'automatically generated' operators and would I figure that out.
I just want a minimum set of operators that implement typical operations
with money (I am using decQuad underlying implementation).
thanks in advance,
Vlad
On Mon, 23 Mar 2009 14:24 +0100, "Thorsten Ottosen"
Steven Watanabe skrev:
AMDG
Archie14 wrote:
ptr_vector<A> lst;
When I need to erase element from this container - should I just do A* el; iterator it = std::find (lst.begin(), lst.end(), el); lst.erase(it);
Replace "A* el" with "A el". Objects are compared not by their pointer value, but by the paointee.
-Thorsten _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -- V S P toreason@fastmail.fm
-- http://www.fastmail.fm - mmm... Fastmail...

At 09:55 AM 3/23/2009, V S P wrote:
I am using this example http://www.boost.org/doc/libs/1_38_0/libs/utility/operators.htm#example
but cannot understand why object is returned from those operators and not an object reference
That certainly is odd. It means that the following code will not work as expected: point x(0,0), y(1,0), z(0,1); (x += y) += z; // x is (1,0), not (1,1).
second, I do not quite understand, what exactly is a set of 'automatically generated' operators and would I figure that out.
It is documented in the comments of the example you cite, and listed in the table[1] just below. [1] http://www.boost.org/doc/libs/1_38_0/libs/utility/operators.htm#smpl_oprs

Thank you for the reply
I am still a bit lost
for example, the doc says
subtractable<T>
produces T operator-(const T&, const T&)
It requires:
"
T temp(t); temp -= t1.
"
so does this mean
T& operator -= (const T& ) ?
---
this is a separate question:
I have implemented the <addable> tempalte with +=
(as in the point example, but made it return a reference)
then I do
cmoney_t a("300");
cmoney_t b("100");
a+=b;
and I see in the debugger that
the *this in the operator += points to 100, not to 300
I am sure I am doing something wrong, but I thought
in the += operator, *this would mean the value of "a" variable
not "b".
Is at least my understanding correct, that *this should be pointing to
300,
and not 100?
thank you again,
Vlad
On Mon, 23 Mar 2009 10:41 -0500, "Alan M. Carroll"
At 09:55 AM 3/23/2009, V S P wrote:
I am using this example http://www.boost.org/doc/libs/1_38_0/libs/utility/operators.htm#example
but cannot understand why object is returned from those operators and not an object reference
That certainly is odd. It means that the following code will not work as expected:
point x(0,0), y(1,0), z(0,1); (x += y) += z; // x is (1,0), not (1,1).
second, I do not quite understand, what exactly is a set of 'automatically generated' operators and would I figure that out.
It is documented in the comments of the example you cite, and listed in the table[1] just below.
[1] http://www.boost.org/doc/libs/1_38_0/libs/utility/operators.htm#smpl_oprs
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -- V S P toreason@fastmail.fm
-- http://www.fastmail.fm - I mean, what is it about a decent email service?

Hi,
please ignore this last question
I figured out the problem
I was using decPlus which adds 0 to the argument
and I needed to use decAdd (which adds the two numbers)
thank you again,
Vlad
On Mon, 23 Mar 2009 12:54 -0400, "V S P"
Thank you for the reply
I am still a bit lost
for example, the doc says
subtractable<T>
produces T operator-(const T&, const T&)
It requires: " T temp(t); temp -= t1. "
so does this mean T& operator -= (const T& ) ?
--- this is a separate question:
I have implemented the <addable> tempalte with += (as in the point example, but made it return a reference)
then I do cmoney_t a("300"); cmoney_t b("100");
a+=b;
and I see in the debugger that the *this in the operator += points to 100, not to 300
I am sure I am doing something wrong, but I thought in the += operator, *this would mean the value of "a" variable not "b".
Is at least my understanding correct, that *this should be pointing to 300, and not 100?
thank you again, Vlad
On Mon, 23 Mar 2009 10:41 -0500, "Alan M. Carroll"
wrote: At 09:55 AM 3/23/2009, V S P wrote:
I am using this example http://www.boost.org/doc/libs/1_38_0/libs/utility/operators.htm#example
but cannot understand why object is returned from those operators and not an object reference
That certainly is odd. It means that the following code will not work as expected:
point x(0,0), y(1,0), z(0,1); (x += y) += z; // x is (1,0), not (1,1).
second, I do not quite understand, what exactly is a set of 'automatically generated' operators and would I figure that out.
It is documented in the comments of the example you cite, and listed in the table[1] just below.
[1] http://www.boost.org/doc/libs/1_38_0/libs/utility/operators.htm#smpl_oprs
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -- V S P toreason@fastmail.fm
-- http://www.fastmail.fm - I mean, what is it about a decent email service?
-- V S P toreason@fastmail.fm -- http://www.fastmail.fm - Or how I learned to stop worrying and love email again

At 11:54 AM 3/23/2009, V S P wrote:
for example, the doc says subtractable<T>
produces T operator-(const T&, const T&)
It requires: " T temp(t); temp -= t1. " so does this mean T& operator -= (const T& ) ?
It means that T must have 1) A public (possibly explicit) copy constructor ("T temp(t)") 2) A public operator -= that takes an argument convertible from T. ("temp -= t1"). T& T::operator -= (T const&) would satisfy this criteria, but it is not the only way. I ignored your other question because of your request to do so.

Archie14 pravi:
I have
ptr_vector<A> lst;
When I need to erase element from this container - should I just do A* el; iterator it = std::find (lst.begin(), lst.end(), el); lst.erase(it);
or
A* el; iterator it = std::find (lst.begin(), lst.end(), el); delete lst.erase(el);
When you erase a pointer from ptr_vector it will delete it.
participants (6)
-
Alan M. Carroll
-
anony
-
Archie14
-
Steven Watanabe
-
Thorsten Ottosen
-
V S P