title: std::forward_list -- erasing with a stored iterator
body: <p>I'm trying to keep a global list of a particular (base) class's instances so that I can track them down by iterating through this global list at any time. </p>
  
  <p>I believe the most proper way to address this is with an intrusive list. I have heard that one can encounter these creatures by digging into the Linux kernel, for example.</p>
  
  <p>In the situation where I'm in, I don't really need such guarantees of performance, and using intrusive lists will complicate matters somewhat for me. </p>
  
  <p>Here's what I've got so far to implement this concept of a class that knows about all of its instances. </p>
  
  <pre><code>class A {
      static std::forward_list&lt;A*&gt; globallist;
      std::forward_list&lt;A*&gt;::iterator listhandle;
  public:
      A() {
          globallist.push_front(this);
          listhandle = globallist.begin();
      }
      virtual ~A() {
          globallist.erase_after(...);  // problem
      }
  };
  </code></pre>
  
  <p>The problem is that there is no <code>forward_list::erase()</code>, and it really does not appear like saving <code>globallist.before_begin()</code> in the ctor would do me much good. I'm never supposed to dereference <code>before_begin()</code>'s iterator. Will it actually hold on to the position? If I save out <code>before_begin</code>'s iterator, and then <code>push_front()</code> a new item, that iterator is probably still not capable of being dereferenced, but will it be serviceable for sending to <code>erase_after()</code>?</p>