Merge pull request #6304 from razvanc-r/master

(Array) .pop_front, .pop_back & .remove return values instead of void
This commit is contained in:
Rémi Verschelde 2016-10-03 11:34:03 +02:00 committed by GitHub
commit cf4693cf18
3 changed files with 19 additions and 9 deletions

View File

@ -276,16 +276,26 @@ void Array::push_front(const Variant& p_value) {
_p->array.insert(0,p_value);
}
void Array::pop_back(){
Variant Array::pop_back(){
if (!_p->array.empty())
_p->array.resize( _p->array.size() -1 );
if (!_p->array.empty()) {
int n = _p->array.size() - 1;
Variant ret = _p->array.get(n);
_p->array.resize(n);
return ret;
}
return Variant();
}
void Array::pop_front(){
if (!_p->array.empty())
Variant Array::pop_front(){
if (!_p->array.empty()) {
Variant ret = _p->array.get(0);
_p->array.remove(0);
return ret;
}
return Variant();
}

View File

@ -80,8 +80,8 @@ public:
void erase(const Variant& p_value);
void push_front(const Variant& p_value);
void pop_back();
void pop_front();
Variant pop_back();
Variant pop_front();
Array(const Array& p_from);
Array(bool p_shared=false);

View File

@ -465,8 +465,8 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM0R(Array,hash);
VCALL_LOCALMEM1(Array,push_back);
VCALL_LOCALMEM1(Array,push_front);
VCALL_LOCALMEM0(Array,pop_back);
VCALL_LOCALMEM0(Array,pop_front);
VCALL_LOCALMEM0R(Array,pop_back);
VCALL_LOCALMEM0R(Array,pop_front);
VCALL_LOCALMEM1(Array,append);
VCALL_LOCALMEM1(Array,resize);
VCALL_LOCALMEM2(Array,insert);