I’m looking for a way to use std::set::const_iterator as const_iterator of my own class.
My code (which actually behaves correct and compiles fine), goes like:
class MyClass{
public:
typedef std::set<T>::const_iterator const_iterator;
const_iterator begin() const {
return mySet->begin();
}
const_iterator end() const {
return mySet->end();
}
}; // MyClass
So, my question is: Is my way of using the const_iterator acceptable and also in the STL intended form?
Edit: Related question and answers at How to typedef the iterator of a nested container?
Have a look at other C++ Standard Library container adapters like
std::queue.std::queueis just an adapter on top of an underlying container (by default astd::deque).This is exactly the method used in those adapters. Given that, I would say your implementation is fine.