Talk:cpp/string/basic string/compare

Comparison description incorrect?
This text from the page: The first one is a substring of the current string, the second one  is a substring of a supplied character sequence. If sizes of the sequences do not match, the shorter sequence is considered being less than the longer sequence. If the sizes of the sequences match, character values are compared. The comparison is done by calling. For default strings this function does the comparison lexicographically.

Seems completely backwards to me. According to the standard (and all three implementations I have looked at), int compare(const basic_string& str) Effects: Determines the effective length rlen of the strings to  compare  as   the  smallest  of size and str.size. The function then compares the two  strings  by  calling  traits::compare(data,  str.data,   rlen). Returns: the nonzero result if the result of the comparison is nonzero. Oth- erwise, returns a value as indicated in Table 10: Table 10--compare results ++                 |     Condition         Return Value | ++                 |size <  str.size   < 0          | |size == str.size    0          | |size > str.size   > 0          | ++

This means that the function first calls traits::compare on the first rlen characters of each string, where rlen is the smaller of the two string sizes. If traits::compare returns non-zero, that value is returned immediately. If and only if traits::compare returns zero (indicating that first rlen characters compare equal) do the relative sizes of the string come into play. 130.20.187.25 11:13, 10 February 2012 (PST)


 * Yes, it is incorrect. Thank you for pointing that out! --Cubbi 12:10, 10 February 2012 (PST)

noexcept of compare(const charT *) [4]
According to 21.4.7.9-4 of the standard, overload 4 has no specification. It's declared as.


 * yes, it can certainly throw as defined in the standard. Updated, thank you for bringing this up. --Cubbi (talk) 06:47, 5 December 2014 (PST)

pos1? count1?
Any particular reason why overloads that take only one parameter of a given name (2, 5, and 6) have a number to that parameter's name? --DevSolar (talk) 11:46, 9 February 2016 (PST)
 * my guess is to make the Parameters table shorter. --Cubbi (talk) 12:05, 9 February 2016 (PST)