Topic: string class, position/size argument conflict?


Author: jgk@netcom.com (Joe Keane)
Date: Wed, 14 Dec 1994 19:44:54 GMT
Raw View
It looks like, in general, when you pass an integer to the string class, you
have no idea what it means.  Personally, for these arguments, i'd prefer using
some very simple classes that are just wrappers around size_t.  For example:

 string s1(capacity_hint(64));
 string s2('s', repeat_count(16));
 string s3("Hello", max_size(4));
 string s4("da", repeat_count(3));
 string s5("bored", start_position(3));

These are probably more verbose than necessary, but you get the idea.

--
Joe Keane, amateur mathematician




Author: harald@bion.kth.se (Harald Winroth)
Date: 05 Dec 1994 13:34:10 GMT
Raw View
I have a question regarding the proposed string class. In the WP of 20 Sep
there are string member functions taking both string and char* arguments.
For example, there are

        class basic_string : ... {
          ...
                basic_string& append(const basic_string& str, size_t pos=0,
                                     size_t n=NPOS);
                basic_string& append(const charT* s, size_t n);
          ...
        };

As I understand the WP,

        str.append("abc123", 3)

would append "abc" to str, while

        str.append((string)"abc123", 3)

would append "123" to str. Is that interpretation correct? If so, I think
this could cause a lot of bugs in application code. As a teacher in C++, I
had hoped that my students could (more or less) forget about char* and
consider "..." to be string literals. However, the example above shows
that they can't. Is there a good reason why string member function taking
charT* arguments won't also take the same position/size arguments as their
basic_string&-argument counterparts?

-----------------------------------------------------------------------------
Harald Winroth     | Computational Vision and Active Perception Laboratory,
harald@bion.kth.se | Royal Institute of Technology, S-10044 Stockholm, Sweden
-----------------------------------------------------------------------------