Re: A question about the std::set<>::iterator
Renzr wrote:
[..] I have two questions.
1st, Why not std::set<> offer operator [i], where i is the local
index?
Because 'std::set' is not a sequential container. Only sequences
are required to provide indexing.
2nd, Why not std::set<>::iterator is invalid in "iterator- begin()"?
Because it's not a random-access iterator. It's a bidirectional
iterator that is not required to provide the subtraction operator.
You need to decide on what container to use based on which part of
its functionality you use the most. If it's insertion and iteration,
and rarely getting the "index", 'std::set' would do nicely. If you
insert rarely (or only once), and then you need to index within the
container the rest of its life, you might be better off with the
vector, as you pointed out. Yes, you need it sorted, but that's
not as expensive as you might think. If you know the maximum # of
DOF, you can reserve a certain size in your vectors to prevent
reallocations when inserting.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask