By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Is it correct to call string::substr(npos+1)?

P: n/a
npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.

Sep 18 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Alien wrote:

npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.
The value of npos is implementation defined. On many platforms it is
-1, but there is no requirement that that be the case. So don't rely
on it.

Best regards,

Tom

Sep 18 '06 #2

P: n/a
So, it's not defined in the standard?

Thomas Tutone wrote:
Alien wrote:

npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.

The value of npos is implementation defined. On many platforms it is
-1, but there is no requirement that that be the case. So don't rely
on it.

Best regards,

Tom
Sep 18 '06 #3

P: n/a
Alien wrote:
npos is defined as -1, in both SGI and VS.
Actually, it is defined that way in the standard [21.3/6]

So npos+1=0?
As long as npos is an unsigned integral type (which it is): yes.

I remember that I read a book saying that npos+1==npos.
Well, that would be false.
Best

Kai-Uwe Bux
Sep 18 '06 #4

P: n/a
Thomas Tutone wrote:
Alien wrote:

npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.
The value of npos is implementation defined. On many platforms it is
-1, but there is no requirement that that be the case. So don't rely
on it.
Alien wrote:
So, it's not defined in the standard?
Kai-Uwe Bux has proven me wrong. It's defined in std::basic_string as
const size_type npos = -1;

I would have sworn Jossutis said it was implementation-defined.

Sorry to lead you astray.

Best regards,

Tom

Sep 18 '06 #5

P: n/a
Thomas Tutone wrote:
>Thomas Tutone wrote:
>>Alien wrote:
npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.
The value of npos is implementation defined. On many platforms it is
-1, but there is no requirement that that be the case. So don't rely
on it.

Alien wrote:
>So, it's not defined in the standard?

Kai-Uwe Bux has proven me wrong. It's defined in std::basic_string as
const size_type npos = -1;

I would have sworn Jossutis said it was implementation-defined.
He should have been right, except that it was originaly unspecified, not
implementation defined. Its purpose was to provide a sentinel value,
nothing more. Somehow unspecified got changed to -1, and that's led far
too many people to write code based on that particular value.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Sep 18 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.