Topic: Bug in draft for string class?


Author: Arch Robison <robison@kai.com>
Date: 1997/03/14
Raw View
This looks like a bug in the December 1996 draft, or if not,
specification of a questionable feature.

Paragraph 5-6 of 21.3.6.8 [lib.string::compare] says:

 int compare(size_type pos, size_type n1,
      charT *s, size_type n2 = npos ) const;

 Returns:

 basic_string<charT,traits,Allocator>(*this,pos,n1).compare(
       basic_string<charT,traits,Allocator>(s,n2))


Paragraph 5-7 of 21.3.1 [lib.string.cons] says:

 basic_string(const charT* s, size_type n,
       const Allocator& a = Allocator())
 ...
 Throws: out_of_range if n==npos

So if I call method compare with the default value for argument n2,
the method *must* throw an exception.  What good is the default
value then?  Why not leave out the default and catch the omission at
compile time?

Arch D. Robison       Kuck & Associates Inc.
robison@kai.com       1906 Fox Drive
217-356-2288        Champaign IL 61820
Lead Developer for KAI C++     http://www.kai.com/C_plus_plus/index.html
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]