mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-06-10 06:12:29 -06:00
Core: Vector::Create, Array::Create improved (thanks Novo)
git-svn-id: svn://ultimatepp.org/upp/trunk@11556 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
88a5acc69a
commit
ccefea34e5
3 changed files with 13 additions and 8 deletions
|
|
@ -98,7 +98,7 @@ public:
|
|||
T& Add(const T& x) { return items < alloc ? *(new(Rdd()) T(clone(x))) : GrowAdd(x); }
|
||||
T& Add(T&& x) { return items < alloc ? *(::new(Rdd()) T(pick(x))) : GrowAddPick(pick(x)); }
|
||||
template <class... Args>
|
||||
T& Create(Args... args) { if(items >= alloc) GrowF(); return *(::new(Rdd()) T(args...)); }
|
||||
T& Create(Args&&... args) { if(items >= alloc) GrowF(); return *(::new(Rdd()) T(std::forward<Args>(args)...)); }
|
||||
void AddN(int n);
|
||||
const T& operator[](int i) const { return Get(i); }
|
||||
T& operator[](int i) { return Get(i); }
|
||||
|
|
@ -243,7 +243,7 @@ public:
|
|||
T& Add(T&& x) { T *q = new T(pick(x)); vector.Add(q); return *q; }
|
||||
T& Add(T *newt) { vector.Add(newt); return *newt; }
|
||||
template<class TT, class... Args>
|
||||
TT& Create(Args... args) { TT *q = new TT(args...); Add(q); return *q; }
|
||||
TT& Create(Args&&... args) { TT *q = new TT(std::forward<Args>(args)...); Add(q); return *q; }
|
||||
const T& operator[](int i) const { return Get(i); }
|
||||
T& operator[](int i) { return Get(i); }
|
||||
int GetCount() const { return vector.GetCount(); }
|
||||
|
|
|
|||
|
|
@ -121,12 +121,11 @@ can be either T or a type derived from T. No constructor is applied.
|
|||
[s7; [*/ Return value]-|Reference to the new element (that is [* `*newt]).&]
|
||||
[s0;*%- &]
|
||||
[s4;%- &]
|
||||
[s5;:Array`:`:Create`(`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 TT][@(0.0.255) >]_
|
||||
[*@4 TT][@(0.0.255) `&]_[* Create]()&]
|
||||
[s2; Creates and adds a new element to the Array.&]
|
||||
[s6; Requires T to have default constructor.&]
|
||||
[s7; [*C@4 TT]-|Type of the new element.&]
|
||||
[s7; [*/ Return value]-|Reference to the newly created element.&]
|
||||
[s5;:Upp`:`:Array`:`:Create`(Args`&`&`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) c
|
||||
lass]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* Create]([*@4 Args][@(0.0.255) `&
|
||||
`&...]_[*@3 args])&]
|
||||
[s2; Creates and adds a new element to the Array. [%-*@3 args] are
|
||||
forwarded to constructor.&]
|
||||
[s3;%- &]
|
||||
[s4;%- &]
|
||||
[s5;:Array`:`:operator`[`]`(int`)const:%- [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[* operat
|
||||
|
|
|
|||
|
|
@ -106,6 +106,12 @@ s...]_[*@4 Args]>_[*@4 T][@(0.0.255) `&]_[* Create]([*@4 Args][@(0.0.255) ...]_a
|
|||
&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:Vector`:`:Create`(Args`&`&`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) c
|
||||
lass...]_[*@4 Args]>_[*@4 T][@(0.0.255) `&]_[* Create]([*@4 Args][@(0.0.255) `&`&...]_args)&]
|
||||
[s2; Creates and adds a new element to the Array. [%-*@3 args] are
|
||||
forwarded to constructor.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Vector`:`:AddN`(int`):%- [@(0.0.255) void]_[* AddN]([@(0.0.255) int]_[*@3 n])&]
|
||||
[s2; Adds specified number of default constructed elements to Vector.&]
|
||||
[s6; Requires T to have default constructor.&]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue