C++ Logo

std-discussion

Advanced search

Re: Why is size_type in std::array an alias for size_t?

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 14 Nov 2019 07:42:16 -0800
On Wednesday, 13 November 2019 22:29:30 PST Wilhelm Meier via Std-Discussion
wrote:
> The point is to use
>
> std::array<A, 5> a;
>
> auto x{a.size()}; // uint8_t
>
> or
>
> std::array<A, 5>::size_type y{}; // uint8_t

Why would you want that?

Don't answer "microcontrollers" and "performance", since uint8_t will get
promoted to int when used and return types are returned in register-sized
chunks.

> In highly templated code the size_type "propagates" through the
> templates and produces optimal code by choosing the "right" type in all
> places.

Using a register-sized type is "highly optimised".

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

Received on 2019-11-14 09:44:38