Re: basic_string::npos
From: Andrey Tarasevich (andreytarasevich_at_hotmail.com)
Date: 10/30/03
- Next message: Ulrich Eckhardt: "Re: templated class in microsoft visual c++ 7.0"
- Previous message: Jumbo: "Re: 0.1 = 0 ???"
- In reply to: Gene Wirchenko: "basic_string::npos"
- Next in thread: Micah Cowan: "Re: basic_string::npos"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Oct 2003 14:34:52 -0800
Gene Wirchenko wrote:
> ...
> basic_string::npos
> static const size_type npos = -1;
> The constant is the largest representable value of type size_type. It
> is assuredly larger than max_size(), hence it serves as either a very
> large value or as a special code."
>
> 1) -1 is assuredly larger than the length of the longest sequence
> that a string can control?
No, '-1' isn't. But the value of 'npos' after initializing it with '-1' is.
The important detail here is that 'std::basic_string<>::size_type' is an
_unsigned_ type. Unsigned types in C++ implement arithmetic modulo 2^n,
where 'n' is the number of bits in the value representation of the type.
For this reason, initializing a value of unsigned type with '-1' is the
same as initializing it with maximum value of that unsigned type.
> 2) Despite
> #include <string>
> I am not able to refer to this value anyway.
How are you trying to refer to it? Post a short example.
-- Best regards, Andrey Tarasevich
- Next message: Ulrich Eckhardt: "Re: templated class in microsoft visual c++ 7.0"
- Previous message: Jumbo: "Re: 0.1 = 0 ???"
- In reply to: Gene Wirchenko: "basic_string::npos"
- Next in thread: Micah Cowan: "Re: basic_string::npos"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|