Home » U++ Library support » U++ Core » Proposal: add Vector::InsertPick(int i, pick_ T&)
|
|
|
|
Re: Proposal: add Vector::InsertPick(int i, pick_ T&) [message #21198 is a reply to message #21194] |
Sat, 09 May 2009 00:05 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
luzr wrote on Fri, 08 May 2009 23:21 |
Mindtraveller wrote on Fri, 08 May 2009 04:30 | Actually it doesn`t. Differences are:
- you require M to have default constructor, which is not strong requirement for Vector element
|
1. Does it?
Quote: |
- you have one redundant call (ctor and operator= instead of ctor), which sometimes is crucial (picking was made for efficiency, right?)
And IMO this code is little bit less clear than plain v.InsertPick(a).
|
2. While I can agree with symmetry point and clarity issue, I do not see how adding InsertPick should solve above problem.
3. Maybe you can rewrite mrjt's example with InsertPick?
Mirek
|
1. I`m not quite shure I understand what you mean by this question.
If I understand correctly and the question is about default ctor requirement, TheIDE help says:
Quote: | General requirement: T is required to be moveable and must have either deep copy constructor, pick constructor or default constructor.
AddPick requirement: void AddPick(pick_ T& x)
Adds new element to Vector and picks value of parameter to it.
Requires T to have pick constructor.
|
-- so it is not necessary for M to have default /deep copy ctor to have Vector<M> and do AddPick.
2. I hope that InsertPick won`t make me writing default constructors or optional deep copy to insert element into queue. This should solve the problem with deep copy where I want to pick only.
3.Vector<M> v;
M a;
..
v.InsertPick(a);
Or maybe you mean InsertPick(int i, pick_ Vector<M> &) ?
[Updated on: Sat, 09 May 2009 00:09] Report message to a moderator
|
|
|
|
|
|
Re: Proposal: add Vector::InsertPick(int i, pick_ T&) [message #21246 is a reply to message #21201] |
Sun, 10 May 2009 19:56 |
hans
Messages: 44 Registered: March 2006 Location: Germany
|
Member |
|
|
Hi,
I think
template <class T>
void Vector<T>::InsertPick(int i, pick_ T& x)
{
if(!count) return;
ASSERT(&x < vector || &x > vector + items);
RawInsert(q, count);
::new(vector[q]) T(x);
}
is wrong, should be:
template <class T>
void Vector<T>::InsertPick(int q, pick_ T& x)
{
ASSERT(&x < vector || &x > vector + items);
RawInsert(q, 1);
::new(vector[q]) T(x);
}
Thanks, Hans.
[Updated on: Sun, 10 May 2009 19:57] Report message to a moderator
|
|
|
Re: Proposal: add Vector::InsertPick(int i, pick_ T&) [message #21255 is a reply to message #21246] |
Sun, 10 May 2009 23:11 |
|
mirek
Messages: 14038 Registered: November 2005
|
Ultimate Member |
|
|
hans wrote on Sun, 10 May 2009 13:56 | Hi,
I think
template <class T>
void Vector<T>::InsertPick(int i, pick_ T& x)
{
if(!count) return;
ASSERT(&x < vector || &x > vector + items);
RawInsert(q, count);
::new(vector[q]) T(x);
}
is wrong, should be:
template <class T>
void Vector<T>::InsertPick(int q, pick_ T& x)
{
ASSERT(&x < vector || &x > vector + items);
RawInsert(q, 1);
::new(vector[q]) T(x);
}
Thanks, Hans.
|
Thank you, you are right, of course.
Mirek
|
|
|
Goto Forum:
Current Time: Fri Sep 20 08:48:36 CEST 2024
Total time taken to generate the page: 0.02833 seconds
|