Boost logo

Boost :

From: scleary_at_[hidden]
Date: 1999-12-29 15:38:45


Darin -

You know, the exact same problem exists when using the Standard library:

  struct CatalogEntry
  {
    string name;
    bool operator==(const string & other) const { return (name == other); }
    // similar ops for !=, <, >, <=, >=
  };
  class Catalog
  {
    private:
      // hide implementation
      vector<CatalogEntry> cat;
    public:
      // provide iterators
      typedef vector<CatalogEntry>::iterator iterator; // ...
      iterator begin() { return cat.begin(); } // ...

      // prerequisite: a CatalogEntry with this name does exist in the
catalog
      void erase(const string & name)
      {
        cat.erase(find(cat.begin(), cat.end(), name));
        cout << "entry " << name << " was removed" << endl;
      }
  };

  void remove_entry(Catalog & catalog, Catalog::iterator entry)
  {
    catalog.erase(entry->name);
  }

Here the STL protects itself with nothing more than documenting when
iterators and references become invalid.

I just wanted to point this out; however, I still think we should return by
(const) object because we are talking about properties here, not iterators.

        -Steve


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk