M
Mark P
What should be the output of the following program? The SGI STL docs
say that all iterators remain valid during a splice operation. The
dinkumware library reference says that iterators to spliced elts. may be
invalidated. I have one system (Linux gcc) which outputs:
0
3
and another (HP aCC) which outputs:
0
2
Any clarification would be most appreciated.
Thanks,
Mark
// pasted code
#include <iostream>
using namespace std;
struct S
{
S(int i) : i(i) {}
int i;
};
typedef list<S> sl;
typedef sl::iterator sli;
void print(sl& l)
{
for (sli it = l.begin(); it != l.end(); ++it)
cout << it->i << endl;
}
int main()
{
sl a;
a.push_back(0);
sl b;
b.push_back(1);
sli bi = b.begin();
*bi = 2;
a.splice(a.end(),b);
*bi = 3;
print(a);
}
say that all iterators remain valid during a splice operation. The
dinkumware library reference says that iterators to spliced elts. may be
invalidated. I have one system (Linux gcc) which outputs:
0
3
and another (HP aCC) which outputs:
0
2
Any clarification would be most appreciated.
Thanks,
Mark
// pasted code
#include <iostream>
using namespace std;
struct S
{
S(int i) : i(i) {}
int i;
};
typedef list<S> sl;
typedef sl::iterator sli;
void print(sl& l)
{
for (sli it = l.begin(); it != l.end(); ++it)
cout << it->i << endl;
}
int main()
{
sl a;
a.push_back(0);
sl b;
b.push_back(1);
sli bi = b.begin();
*bi = 2;
a.splice(a.end(),b);
*bi = 3;
print(a);
}