Move Vector Element to the end
<p>I am having an issue moving an element in a Vector to the end of the list of elements. I am using CUtlVector (class from HL2 SDK found here <a href="http://hg.alliedmods.net/hl2sdks/hl2sdk-ob/file/0f3afddb27c9/public/tier1/utlvector.h" rel="nofollow">http://hg.alliedmods.net/hl2sdks/hl2sdk-ob/file/0f3afddb27c9/public/tier1/utlvector.h</a>) and everything seems fine. I did a for loop and printed the contents and they are all correct, but when I call my function to find a usable element, it keeps pulling the same one.</p>

<p>The idea is that it finds the first name that is NAME_AVAILABLE and uses it. The problem seems to be when I am moving it to the end of the list, as it is using the same name everytime I call the function.</p>

<pre><code>typedef std::pair&lt;std::string,int&gt; namePair;
CUtlVector&lt;namePair&gt; g_Names;

// Iterate through Names and find an Unused one
for(int i = 0; i &lt; g_Names.Count(); ++i)
{
    if(g_Names.Element(i).second == NAME_AVAILABLE)
    {
        foundName = true;

        // We found an Available Name. Mark as Unavailable and move it to the end of the list
        char *Name = const_cast&lt;char*&gt;(g_PlayerNames.Element(i).first.c_str());
        g_Players.Element(index)-&gt;name = playerName;

        g_Names.AddToTail(std::pair&lt;char*,int&gt;(Name, NAME_UNAVAILABLE));
        g_Names.Remove(i); // Remove name since we added it to the end of the list

        break;
    }
}
</code></pre>
