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

A

Alien

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.
 
T

Thomas Tutone

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
 
A

Alien

So, it's not defined in the standard?

Thomas said:
Alien wrote:



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
 
T

Thomas Tutone

Thomas said:
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
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
 
P

Pete Becker

Thomas said:
Thomas said:
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


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top