H
Hicham Mouline
Hello,
I have posted this question elsewhere:
The answer given was:
My question was incomplete.
1. I wish to keep the container const and it may be unsorted.
2. I wish to avoid making a copy if possible and would accept a slower
algorithm if there is one.
3. Is it possible to then iterate (possibly by writing a new iterator) over
the distinct elements?
regards,
I have posted this question elsewhere:
Given a std::vector<T> and a Compare<T> comparator, how can I:
1. determine the number of different elements in the vector?
2. get iterators to the list of distinct elements in the vector?
The answer given was:
With 2 iterators b and e,
std::sort(b, e);
m = std::unique(b, e, Compare<T>());
Then you have the std::distance(b, m) unique elements available in the
range [b, m).
My question was incomplete.
1. I wish to keep the container const and it may be unsorted.
2. I wish to avoid making a copy if possible and would accept a slower
algorithm if there is one.
3. Is it possible to then iterate (possibly by writing a new iterator) over
the distinct elements?
regards,