title: Multi-Index Insert Failure Return (Boost)
body: <p>I'm currently using Boost's multi-index to help keep track of how many times a packet passes through a system. </p>
  
  <p>Each time a system touches the packet, its IP address is added to a string, separated by commas. I go through that string then, tokenize it and add each IP found to a multi-index. Since the IPs are set to be unique right now, it's impossible for the same IP to be added twice to the multi-index. What <strong>should</strong> happen then is the value associated with the IP address should be incremented, counting how many times the packet went through that same IP.</p>
  
  <p>Anyways, my issue comes in here. When I use something like stl map, I will get back a response which lets me know a key could not be added due to a duplicate key already existing within the map. Does Boost's multi-index offer anything similar? I know that if I attempt to insert the same IP it will fail, but how can I tell it failed?</p>
  
  <p>Here's a portion of my current code:</p>
  
  <pre><code>// Multi-index handling
  using boost::multi_index_container;
  using namespace boost::multi_index;
  
  struct pathlog
  {
      string         hop;
      int     passedthru;
  
      pathlog(std::string hop_,int passedthru_):hop(hop_),passedthru(passedthru_){}
  
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os,const pathlog&amp; e)
      {
          os&lt;&lt;e.hop&lt;&lt;" "&lt;&lt;e.passedthru&lt;&lt;std::endl;
          return os;
      }
  };
  
  // structs for data
  struct hop{};
  struct passedthru{};
  
  // multi-index container setup
  typedef multi_index_container&lt;
  pathlog,
  indexed_by&lt;
  ordered_unique&lt;
  tag&lt;hop&gt;,  BOOST_MULTI_INDEX_MEMBER(pathlog,std::string,hop)&gt;,
  ordered_non_unique&lt;
  tag&lt;passedthru&gt;, BOOST_MULTI_INDEX_MEMBER(pathlog,int,passedthru)&gt; &gt;
  &gt; pathlog_set;
  
  
  int disassemblepathlog(const string&amp; str, pathlog_set&amp; routecontainer, const string&amp; delimiters = ","){
      // Tokenizer (heavily modified) from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html
  
      // Skip delimiters at beginning.
      string::size_type lastPos = str.find_first_not_of(delimiters, 0);
      // Find first "non-delimiter".
      string::size_type pos     = str.find_first_of(delimiters, lastPos);
  
      while (string::npos != pos || string::npos != lastPos)
      {
          // Found a token, add it to the vector.
          routecontainer.insert(pathlog((str.substr(lastPos, pos - lastPos)),1)); // if this fails, I need to increment the counter!
          // Skip delimiters.  Note the "not_of"
          lastPos = str.find_first_not_of(delimiters, pos);
          // Find next "non-delimiter"
          pos = str.find_first_of(delimiters, lastPos);
      }
  }
  </code></pre>