crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )


  Ответ в size_t, size_type, unsigned
Введите ваше имя
Подтвердите код

Введите в поле код из 6 символов, отображенных в виде изображения. Если вы не можете прочитать код с изображения, нажмите на изображение для генерации нового кода.
 

Опции сообщения
 Включить смайлы?
Иконки сообщения
(Опционально)
                                
                                
  [ Без иконки ]
 


Последние 10 сообщений [ в обратном порядке ]
Andrew Selivanov Дата 4.4.2008, 10:47
  Вот, кажется нашел :) size_type изначально был придуман для аллокаторов, чтобы они поддурживали не только Intel архитектуру ;)

20.1.5 Allocator requirements

4 Implementations of containers described in this International Standard are permitted to assume that their Allocator template parameter meets the following two additional requirements beyond those in Table 32.

— The typedef members pointer, const_pointer, size_type, and difference_type are required to be T*,T const*, size_t, and ptrdiff_t, respectively.

5 Implementors are encouraged to supply libraries that can accept allocators that encapsulate more general memory models and that support non-equal instances. In such implementations, any requirements imposed on allocators by containers beyond those requirements that appear in Table 32, and the semantics of containers and algorithms when allocator instances compare non-equal, are implementation-defined.


А вот что по этому поводу говорит Pete Becker:
http://www.velocityreviews.com/forums/show...mp;postcount=10
If you have ancient copies of the STL documentation from HP, you'll see my name listed as one of the contributors. That's because I "fixed" a problem that Alex Stepanov and Meng Lee had in specifying allocators. They were dealing specifically with the Intel architecture, but that was just a particular instance of a more general problem. So
the true answer is that both of your alternatives are correct: size_type is there for the Intel segmented architecture in particular, and for alternative memory managers in general.
Tonal Дата 4.4.2008, 10:21
  До сих пор не все компиляторы стандарт нормально поддерживают. :)
Litkevich Yuriy Дата 3.4.2008, 18:28
  у меня в WinAVR, такое:
#define     __SIZE_TYPE__   long unsigned int
...
typedef __SIZE_TYPE__     size_t

одно время гадал зачем в некоторых файла написано __need_size_t, так и не понял.
Tonal Дата 3.4.2008, 18:08
  unsigned - ключевое слово языка. Обозначает, что следующий за ним интегральный тип не имеет знака. Допускается употреблять без последующего типа, тогда обозначает unsigned int.

size_t - стандартный (описанный в стандарте) псевдоним (typedef) для типа возвращающегося при запросе размера объекта языка (sizeof). Всегда беззнаковый (отрицательных размеров не бывает) обычно unsigned int, или unsigned long. Вполне представимы и системы с unsigned short int и unsigned long long.

size_type - стандартный псевдоним для типа возвращающегося при запросе размера контейнера совместимого с STL. Вполне может быть любым беззнаковым типом - в зависимости от реализации контейнера.
Andrew Selivanov Дата 3.4.2008, 17:40
  Кто нибудь действительно понимает разницу между ними? Четко где нибудь это разъясняется? Я накопал такое определение:

size_t is the type of the value returned by sizeof(). It is also a
typedef in some standard headers.

size_type is another typedef used for example in the standard
containers, like std::vector and std::string.

unsigned is a standard type that is built into the compiler. As such,
it is available immediately, without any typedefs.

On some systems, size_t, size_type, and unsigned could all be the same
type. On other systems they might be different. By always using the
proper type, your code has a bigger chance of being portable from one
system to another.
Просмотр темы полностью (откроется в новом окне)
RSS Текстовая версия Сейчас: 16.4.2024, 16:34