refactor(list): improve append function
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
24c173a519
commit
1aca1d2d77
1 changed files with 15 additions and 4 deletions
|
@ -86,10 +86,21 @@ std::pair<list<T>, list<T>> split_reverse_second(list<T> const & l) {
|
|||
*/
|
||||
template<typename T>
|
||||
list<T> append(list<T> const & l1, list<T> const & l2) {
|
||||
if (!l1) {
|
||||
return l2;
|
||||
} else if (!l2) {
|
||||
return l1;
|
||||
} else {
|
||||
buffer<T> tmp;
|
||||
list<T> r = l2;
|
||||
to_buffer(l1, tmp);
|
||||
to_buffer(l2, tmp);
|
||||
return to_list(tmp.begin(), tmp.end());
|
||||
unsigned i = tmp.size();
|
||||
while (i > 0) {
|
||||
--i;
|
||||
r = cons(tmp[i], r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue