C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Why is size_type in std::array an alias for size_t?
From: Thiago Macieira (thiago_at_[hidden])
Date: 2019-11-14 09:42:16


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

STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups