Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++.moderated > #2603
| From | Daniel Krügler <daniel.kruegler@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.c++.moderated, comp.lang.c++ |
| Subject | Re: size_type and size_t |
| Date | 2011-12-02 22:35 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <jbb0nq$c7o$1@dont-email.me> (permalink) |
| References | <8ce7855d-ade8-4d83-ad8e-9fec2266c72b@b32g2000yqn.googlegroups.com> <jb308c$bjo$1@dont-email.me> <jb7df6$31l$1@usenet.stanford.edu> |
Cross-posted to 2 groups.
Am 02.12.2011 14:54, schrieb Seungbeom Kim:
> On 2011-11-29 22:33, Daniel Krügler wrote:
> I agree that it's preferable to use string::size_type instead of size_t,
> at least semantically. However, string is defined to be basic_string<char>,
> whose size_type is defined to be allocator<char>::size_type, which is
> in turn defined to be size_t. Therefore, in this particular (and common)
> case, string::size_type is identical to size_t.
You are right, I should have made clearer that my concerns do refer to
programming in template context or any "indirect" context, where you
depend on some type chains. Sometimes I forget that I'm not in such an
"indirect" role ;-)
> Of course, there can be other instantiations of basic_string which use
> an allocator other than the standard one which defines its size_type
> to be a type different from size_t.
Yes.
> My question is: in such cases, does an implementation exist where size_type
> is bigger than size_t, or can one ever exist?
I'm interpreting your question to refer to general allocators, not to
std::allocator. But when I do this, the term "implementation" makes me
wonder a bit (which in this context can also be read as "Library
implementation"), nonetheless I assume you mean the implementation of
some user-defined allocator, I hope this is what you meant.
> On all of not-so-many implementations I have ever
> experienced, size_t was the biggest unsigned integer type, so I have
> a hard time imagining an unsigned integer type bigger than size_t.
There is no indication in either C or C++ that std::size_t corresponds
to the std::umaxint_t from <cstdint>, size_t typically reflects the
"bitness" of the underlying platfom. On my 32 bit machine gcc 4.7 gives
me the following program compiles successfully:
#include <cstdint>
#include <climits>
constexpr std::uintmax_t c1 = UINTMAX_MAX;
constexpr std::size_t c2 = SIZE_MAX;
static_assert(c1 > c2, "Error");
static_assert(sizeof(std::size_t) * CHAR_BIT == 32, "Error");
static_assert(sizeof(std::uintmax_t) * CHAR_BIT == 64, "Error");
I expect that reflects typical PCs with 32 bit architecture.
HTH & Greetings from Bremen,
Daniel Krügler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to comp.lang.c++.moderated | Previous | Next — Previous in thread | Find similar | Unroll thread
C++11 Variadic Templates: Format("I %%% about %%% of %%%","dream", 7, 9) == "I dream about 7 of 9" Andrew Tomazos <andrew@tomazos.com> - 2011-11-28 14:31 -0800
Re: C++11 Variadic Templates: Format("I %%% about %%% of %%%","dream", 7, 9) == "I dream about 7 of 9" legalize+jeeves@mail.xmission.com (Richard) - 2011-11-28 22:58 -0800
Re: C++11 Variadic Templates: Format("I %%% about %%% of %%%","dream", 7, 9) == "I dream about 7 of 9" "news" <newsmaster@tdcnet.fi> - 2011-11-29 22:24 -0800
Re: C++11 Variadic Templates: Format("I %%% about %%% of %%%","dream", 7, 9) == "I dream about 7 of 9" legalize+jeeves@mail.xmission.com (Richard) - 2011-11-30 12:45 -0800
Re: C++11 Variadic Templates: Format("I %%% about %%% of %%%","dream", 7, 9) == "I dream about 7 of 9" Andrew Tomazos <andrew@tomazos.com> - 2011-11-29 22:26 -0800
Re: C++11 Variadic Templates: Format("I %%% about %%% of %%%","dream", 7, 9) == "I dream about 7 of 9" Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-11-29 22:33 -0800
size_type and size_t Seungbeom Kim <musiphil@bawi.org> - 2011-12-02 05:54 -0800
Re: size_type and size_t Jean-Marc Bourguet <jm@bourguet.org> - 2011-12-02 22:33 -0800
Re: size_type and size_t Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-12-02 22:35 -0800
csiph-web