title: Is it safe to modify mutable members of objects inside sets?
body: <p>I was curious as to whether the following scenario is safe.</p>
  
  <p>I have the following class definitions:</p>
  
  <pre><code>class ActiveStatusEffect
  {
  public:
      StatusEffect* effect;
      mutable int ReminaingTurns;
      ActiveStatusEffect() : ReminaingTurns(0)
      {
      }
      //Other unimportant stuff down here
  }
  </code></pre>
  
  <p>I then store a group of these inside an std::set as follows:</p>
  
  <pre><code>struct ASECmp
  {
      bool operator ()(const StatusEffects::ActiveStatusEffect &amp;eff1, const StatusEffects::ActiveStatusEffect &amp;eff2)
      {
          return eff1.effect-&gt;GetPriority() &lt; eff2.effect-&gt;GetPriority();
      }
  };
  std::set&lt;StatusEffects::ActiveStatusEffect, ASECmp&gt; ActiveStatusEffects;
  </code></pre>
  
  <p>I mark RemainingTurns as mutable because I want to be able to change it without haing to constantly erase/insert into the set. I.e.</p>
  
  <pre><code>void BaseCharacter::Tick(Battles::BattleField &amp;field, int ticks)
  {
      for (auto effect = ActiveStatusEffects.begin(); effect != ActiveStatusEffects.end();)// ++index)
      {
             auto next = effect;
              ++next;
          if (effect-&gt;effect-&gt;HasFlag(StatusEffects::STATUS_FLAGS::TickEffect) &amp;&amp; effect-&gt;ReminaingTurns &gt; 0)
          {                       
              effect-&gt;effect-&gt;TickCharacter(*this, field, ticks);
              --effect-&gt;ReminaingTurns;
  
          }
          if (effect-&gt;ReminaingTurns == 0)
          {
              ActiveStatusEffects.erase(effect);
          }
          effect = next;
      }
  }
  </code></pre>
  
  <p>I'm concerned because it seems possible for this to mess up the ordering within the set, meaning I can't guarantee the set will always be sorted by effect->GetPrority()</p>
  
  <p>If that's true, is there a safe way (such as not have RemainingTurns form part of the key) to do this besides copying, modifying, erasing then inserting what I need to change?</p>
  
  <p>EDIT:</p>
  
  <p>@ildjarn - sorry, I didn't think that mattered. It just returns an int stored within StatusEffect. That int is guaranteed not to change over the runtime of the program.</p>
  
  <pre><code>int StatusEffect::GetPriority() const
  {
      return StatusPriority;
  }
  </code></pre>