C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Risks of using std::extent on non-built-in array types

From: Robin Savonen Söderholm <robinsavonensoderholm_at_[hidden]>
Date: Fri, 13 Dec 2024 18:22:30 +0100
I go with Thiago here: you are using std::extent weirdly.. Go with
std::(ranges::)size or (better yet) ranged for-loop. Doing some search for
std::extent and manually replacing it with something more purpose-built is
probably your best bet.

On Fri, Dec 13, 2024, 18:05 Andre Kostur via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> To be fair, there may be 6+ years of code out there already using
> std::extent::value (and the concern is updating existing code).
>
> I’m pondering whether suggesting adding a specialization for std::array
> would be better. But raises the question if there was a dependency by
> someone on extents of std::array returning 0.
>
> On Fri, Dec 13, 2024 at 8:53 AM Thiago Macieira via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> On Friday 13 December 2024 12:09:06 Brasilia Standard Time Yexuan Xiao
>> via
>> Std-Proposals wrote:
>> > for(std::size_t i{}; i != std::extent_v<arr>; ++i) { /* */ };
>>
>> Write instead:
>>
>> for (std::size_t i = 0; i != std::size(arr); ++i)
>>
>> with arr here being the actual array variable instead of the array type.
>>
>> --
>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>> Principal Engineer - Intel DCAI Platform & System Engineering
>>
>>
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-12-13 17:22:46