E
equation .
Hi,
what is the best way to insert the contents of std::list to the end of
the
same list? I haven't used C++ much recently (actually, in quite some
time)
and I can't tell if there's a much simpler way to achieve the
following
(the appending functionality - this is just an example) - assuming
it's
correct and portable and not just happening to work on my system.
#include <list>
struct A {
std::list<type> list;
void append(const std::list<type>& other)
{
if (&list != &other) {
list.insert(list.end(), other.begin(), other.end());
} else if (!list.empty()) {
std::list<type>::iterator end = list.end();
--end;
list.insert(list.end(), list.begin(), end);
list.push_back(*end);
}
}
};
what is the best way to insert the contents of std::list to the end of
the
same list? I haven't used C++ much recently (actually, in quite some
time)
and I can't tell if there's a much simpler way to achieve the
following
(the appending functionality - this is just an example) - assuming
it's
correct and portable and not just happening to work on my system.
#include <list>
struct A {
std::list<type> list;
void append(const std::list<type>& other)
{
if (&list != &other) {
list.insert(list.end(), other.begin(), other.end());
} else if (!list.empty()) {
std::list<type>::iterator end = list.end();
--end;
list.insert(list.end(), list.begin(), end);
list.push_back(*end);
}
}
};