I have a class Foothat contains mapand provides functions begin()and end()to iterate through it:
class Foo {
typedef std::map<int, double> Container;
typedef Container::const_iterator const_iterator;
Container c_;
public:
const_iterator begin() const { return c_.begin(); }
const_iterator end() const { return c_.end(); }
void insert(int i, double d) { c_[i] = d; }
};
Now I would like to change it inside std::map<int, double>only to std::set<int>, but I do not want to break the client code.
So, double dthe function is insertnow simply ignored. And the following code should remain valid where it->secondit will always be 0.0:
Foo foo;
for(Foo::const_iterator it = foo.begin(); it != foo.end(); ++it) {
std::cout << it->first << " " << it->second << std::endl;
}
How can I make these changes to the class Foo?
In other words, how can I provide Foo::const_iteratorthat adapts the new inner std::set<int>::const_iteratorto behave like the old std::map<int,double>::const_iterator?
: , map, - . Foo double .