title: How to compare a "basic_string" using an arbitary locale
body: <p>I'm re-posting a question I submitted earlier today but I'm now citing a specific example in response to the feedback I received. The original question can be found <a href="https://stackoverflow.com/questions/23269449/why-are-basic-string-and-locale-so-difficult-to-use-in-c">here</a> (note that it's not a homework assignment):</p>
  
  <p>I'm simply trying to determine if C++ makes it impossible to perform an (efficient) <strong>case-INsensitive</strong> comparison of a <code>basic_string</code> object that also factors in any arbitrary <code>locale</code> object. For instance, it doesn't appear to be possible to write an efficient function such as the following:</p>
  
  <pre><code>bool AreStringsEqualIgnoreCase(const string &amp;str1, const string &amp;str2, const locale &amp;loc);
  </code></pre>
  
  <p>Based on my current understanding (but can someone confirm this), this function <em>has</em> to call both <code>ctype::toupper()</code> and <code>collate::compare()</code> for the given <code>locale</code> (extracted as always using <code>use_facet()</code>). However, because <code>collate::compare()</code> in particular requires 4 pointer args, you either need to pass these 4 args for every char you need to compare (after first calling <code>ctype::toupper()</code>), or alternatively, convert both strings to upppercase first and then make a single call to <code>collate::compare()</code>. </p>
  
  <p>The 1st approach is obviously inefficient (4 pointers to pass for each char tested), and the 2nd requires you to convert both strings to uppercase in their entirety (requiring allocation of memory and needless copying/converting of both strings to uppercase). Am I correct about this, i.e.,  it's not possible to do it efficiently (because there's no way around <code>collate::compare()</code>).</p>