Core: Array/Vector Set, Insert, InsertPick now return a reference to the element

git-svn-id: svn://ultimatepp.org/upp/trunk@3344 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-04-16 18:24:01 +00:00
parent 3c5b635f22
commit 5a44fdd2d5
4 changed files with 49 additions and 19 deletions

View file

@ -63,14 +63,16 @@ public:
void Reserve(int n);
int GetAlloc() const { return alloc; }
void Set(int i, const T& x, int count = 1);
void Set(int i, const T& x, int count);
T& Set(int i, const T& x) { Set(i, x, 1); return Get(i); }
void Remove(int i, int count = 1);
void Remove(const int *sorted_list, int n);
void Remove(const Vector<int>& sorted_list);
void InsertN(int i, int count = 1);
T& Insert(int i) { InsertN(i); return Get(i); }
void Insert(int i, const T& x, int count = 1);
void InsertPick(int i, pick_ T& x);
T& Insert(int i) { InsertN(i); return Get(i); }
void Insert(int i, const T& x, int count);
T& Insert(int i, const T& x) { Insert(i, x, 1); return Get(i); }
T& InsertPick(int i, pick_ T& x);
void Insert(int i, const Vector& x);
void Insert(int i, const Vector& x, int offset, int count);
void InsertPick(int i, pick_ Vector& x);
@ -185,14 +187,16 @@ public:
void Reserve(int xtra) { vector.Reserve(xtra); }
int GetAlloc() const { return vector.GetAlloc(); }
void Set(int i, const T& x, int count = 1);
void Set(int i, const T& x, int count);
T& Set(int i, const T& x) { Set(i, x, 1); return Get(i); }
void Remove(int i, int count = 1);
void Remove(const int *sorted_list, int n);
void Remove(const Vector<int>& sorted_list);
void InsertN(int i, int count = 1);
T& Insert(int i) { InsertN(i); return Get(i); }
void Insert(int i, const T& x, int count = 1);
void InsertPick(int i, pick_ T& x);
void Insert(int i, const T& x, int count);
T& Insert(int i, const T& x) { Insert(i, x, 1); return Get(i); }
T& InsertPick(int i, pick_ T& x);
void Insert(int i, const Array& x);
void Insert(int i, const Array& x, int offset, int count);
void Append(const Array& x) { Insert(GetCount(), x); }

View file

@ -273,11 +273,12 @@ void Vector<T>::Insert(int q, const T& x, int count) {
}
template <class T>
void Vector<T>::InsertPick(int q, pick_ T& x)
T& Vector<T>::InsertPick(int q, pick_ T& x)
{
ASSERT(&x < vector || &x > vector + items);
RawInsert(q, 1);
::new(vector[q]) T(x);
return Get(q);
}
template <class T>
@ -448,10 +449,11 @@ void Array<T>::Insert(int i, const T& x, int count) {
}
template <class T>
void Array<T>::InsertPick(int i, pick_ T& x)
T& Array<T>::InsertPick(int i, pick_ T& x)
{
vector.InsertN(i, 1);
vector[i] = new T(x);
return Get(i);
}
template <class T>

View file

@ -267,7 +267,7 @@ current capacity, capacity is increased to the required value.&]
[s3;%- &]
[s4;%- &]
[s5;:Array`:`:Set`(int`,const T`&`,int`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) int]_[*@3 i
], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count]_`=_[@3 1])&]
], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count])&]
[s2; Sets the requested number of elements starting at the position
[* i] to the specified value. If the required number of elements
exceeds existing elements of the Array then elements are added
@ -279,6 +279,12 @@ to the Array.&]
[s7; [*C@3 count]-|Number of elements.&]
[s3;%- &]
[s4;%- &]
[s5;:Array`:`:Set`(int`,const T`&`):%- [*@4 T][@(0.0.255) `&]_[* Set]([@(0.0.255) int]_[*@3 i],
[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&]
[s2; Sets the element at [%-*@3 i] to [%-*@3 x] and returns a reference
to this element.&]
[s3; &]
[s4;%- &]
[s5;:Array`:`:Remove`(int`,int`):%- [@(0.0.255) void]_[* Remove]([@(0.0.255) int]_[*@3 i],
[@(0.0.255) int]_[*@3 count]_`=_[@3 1])&]
[s2; Removes requested number of elements.&]
@ -323,8 +329,7 @@ the specified position.&]
[s3;%- &]
[s4;%- &]
[s5;:Array`:`:Insert`(int`,const T`&`,int`):%- [@(0.0.255) void]_[* Insert]([@(0.0.255) int
]_[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count]_`=_[@3 1
])&]
]_[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count])&]
[s2; Inserts a specified number of elements, setting them to a specified
value.&]
[s6;~~~.992; Requires T to have deep copy constructor.&]
@ -334,9 +339,16 @@ value.&]
[s7; [*C@3 count]-|Number of elements to insert.&]
[s3;%- &]
[s4;%- &]
[s5;:Array`:`:InsertPick`(int`,pick`_ T`&`):%- [@(0.0.255) void]_[* InsertPick]([@(0.0.255) i
[s5;:Array`:`:Insert`(int`,const T`&`):%- [*@4 T][@(0.0.255) `&]_[* Insert]([@(0.0.255) int]_
[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&]
[s2; Inserts an element at [%-*@3 i] setting it to [%-*@3 x] and returns
a reference to it.&]
[s3; &]
[s4;%- &]
[s5;:Array`:`:InsertPick`(int`,pick`_ T`&`):%- [*@4 T][@(0.0.255) `&]_[* InsertPick]([@(0.0.255) i
nt]_[*@3 i], [@(0.128.128) pick`_]_[*@4 T][@(0.0.255) `&]_[*@3 x])&]
[s2; Inserts an element at [%-*@3 i] picking the content of [%-*@3 x].&]
[s2; Inserts an element at [%-*@3 i] picking the content of [%-*@3 x]
and returns a reference to it.&]
[s6;~~~.992; Requires T to have pick constructor.&]
[s6;~~~.992; Invalidates iterators to the Array.&]
[s3; &]

View file

@ -237,7 +237,7 @@ capacity, capacity is increased to the required value.&]
[s3;%- &]
[s4;%- &]
[s5;:Vector`:`:Set`(int`,const T`&`,int`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) int]_[*@3 i
], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count]_`=_[@3 1])&]
], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count])&]
[s2; Sets requested number of elements starting at the position [* i]
to the specified value. If required number of elements exceeds
existing elements of Vector then elements are added to Vector.&]
@ -248,6 +248,12 @@ existing elements of Vector then elements are added to Vector.&]
[s7; [*C@3 count]-|Number of elements.&]
[s3;%- &]
[s4;%- &]
[s5;:Vector`:`:Set`(int`,const T`&`):%- [*@4 T][@(0.0.255) `&]_[* Set]([@(0.0.255) int]_[*@3 i],
[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&]
[s2; Sets element at [%-*@3 i] to [%-*@3 x].and returns a reference to
the element.&]
[s3; &]
[s4;%- &]
[s5;:Vector`:`:Remove`(int`,int`):%- [@(0.0.255) void]_[* Remove]([@(0.0.255) int]_[*@3 i],
[@(0.0.255) int]_[*@3 count]_`=_[@3 1])&]
[s2; Removes requested number of elements.&]
@ -292,8 +298,7 @@ a specified position.&]
[s3;%- &]
[s4;%- &]
[s5;:Vector`:`:Insert`(int`,const T`&`,int`):%- [@(0.0.255) void]_[* Insert]([@(0.0.255) in
t]_[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count]_`=_
[@3 1])&]
t]_[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count])&]
[s2; Inserts a specified number of elements, setting them to a specified
value.&]
[s6;~~~.992; Requires T to have deep copy constructor.&]
@ -303,9 +308,16 @@ value.&]
[s7; [*C@3 count]-|Number of elements to insert.&]
[s3;%- &]
[s4;%- &]
[s5;:Vector`:`:InsertPick`(int`,pick`_ T`&`):%- [@(0.0.255) void]_[* InsertPick]([@(0.0.255) i
[s5;:Vector`:`:Insert`(int`,const T`&`):%- [*@4 T][@(0.0.255) `&]_[* Insert]([@(0.0.255) int]_
[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&]
[s2; Inserts element at position [%-*@3 i] setting its value to [%-*@3 x]
and returns a reference to it.&]
[s3; &]
[s4;%- &]
[s5;:Vector`:`:InsertPick`(int`,pick`_ T`&`):%- [*@4 T][@(0.0.255) `&]_[* InsertPick]([@(0.0.255) i
nt]_[*@3 i], [@(0.128.128) pick`_]_[*@4 T][@(0.0.255) `&]_[*@3 x])&]
[s2; Inserts an element at [%-*@3 i] picking the content of [%-*@3 x].&]
[s2; Inserts an element at [%-*@3 i] picking the content of [%-*@3 x]
and returns a reference to this new element.&]
[s6;~~~.992; Requires T to have pick constructor.&]
[s6;~~~.992; Invalidates iterators and references to Vector.&]
[s3; &]