Topic: Substring compare broken?


Author: dsb@cs.duke.edu (Scott Bigham)
Date: 1995/08/20
Raw View
I'm reading 21.1.1.9.8 [lib.string::compare] from the April 28 draft,
and it seems to require, counterintuitively, that the following program
print a nonzero value:

    #include <string>
    #include <iostream>

    main() {
      string fred("This is a test"), joe("his");
      cout << fred.compare(joe, 1, 3);
      return 0;
    }

since fred.size() - 1 > joe.size() [as per Table 8].  This seems to
utterly vitiate the third parameter.  I suspect (or at least I hope)
that Table 8 is only intended to apply when the third parameter equals
string::npos, or at least is greater than the lengths of the two
strings, but I can't find words to that effect in the section.  Am I
missing something, or is this a genuine problem?

      -sbigham
--
Scott Bigham                   | The opinions expressed above are
dsb@cs.duke.edu                | (c) 1995 Hacker Ltd. and cannot be
http://www.cs.duke.edu/~dsb/   | copied or distributed without a
      = PGP spoken here =      | Darn Good Reason(tm).
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]