Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As to why the <code>::</code> is necessary: the standard defines two <code>tolower</code>'s, a function template in <code>std::</code>, and a simple function in both <code>::</code> and <code>std::</code>. Depending on which headers have been included (and that includes headers indirectly included from other headers, which you may not know about), either one, the other, or both may be visible. Using <code>::</code> ensures that the older one, from the C standard, is used. (If the one in <code>std::</code> is considered, the call will be ambiguous, since transform is a template itself, and the compiler will not be able to deduce the template arguments.)</p> <p>While I'm at it, I might mention that using <code>::tolower</code> like this is undefined behavior, at least if plain char is signed. The input to <code>::tolower</code> is an int, and must be in the range <code>0</code>...<code>UCHAR_MAX</code>, or <code>EOF</code>. If plain char is signed, some of the characters may have negative encodings, which results in undefined behavior. In practice, most implementations make this work. For all characters except <code>0xFF</code> (ÿ in Latin 1). If you're not concerned with portability, some compilers have a switch to make char unsigned---use it. Otherwise, write a small functional object to handle it correctly, either:</p> <pre><code>struct ToLower { char operator()( char ch ) const { return ::tolower( static_cast&lt;unsigned char&gt;(ch) ); } }; </code></pre> <p>or (better, but significantly more work---only worth it if your using it a lot), a functional object whose constructor takes a locale (defaulting to the global locale) and contains a reference to an <code>std::ctype</code>, which it uses for the <code>tolower</code> function. (Of course, if you're really internationalized, <code>tolower</code> probably doesn't have any meaning. And you'll be using UTF-8, which is a multi-byte encoding, and doesn't work with any of the available possibilities.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload