Date: Mon, 23 Oct 2023 12:46:08 +0300
If you pass around span instead of pointer and length then it becomes less
error prone and shorter - https://godbolt.org/z/Y4WqPM3r4
#include <span>
int get();
void fun(int* p, unsigned len)
{
for ( unsigned i = 0u; i < len; ++i ) *p++ = get();
}
void more_fun(int* p, unsigned len)
{
for (auto& e : std::span{p, len}) e = get();
}
void best_fun(std::span<int> buff)
{
for (auto& e : buff) e = get();
On Mon, Oct 23, 2023 at 12:18 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
> What if the following:
>
> for ( usigned i = 0u; i < len; ++i ) *p++ = Get();
>
> Could be written as simply:
>
> for ( len ) *p++ = Get();
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
error prone and shorter - https://godbolt.org/z/Y4WqPM3r4
#include <span>
int get();
void fun(int* p, unsigned len)
{
for ( unsigned i = 0u; i < len; ++i ) *p++ = get();
}
void more_fun(int* p, unsigned len)
{
for (auto& e : std::span{p, len}) e = get();
}
void best_fun(std::span<int> buff)
{
for (auto& e : buff) e = get();
On Mon, Oct 23, 2023 at 12:18 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
> What if the following:
>
> for ( usigned i = 0u; i < len; ++i ) *p++ = Get();
>
> Could be written as simply:
>
> for ( len ) *p++ = Get();
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2023-10-23 09:46:19