C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Only reason I don't use std::array

From: Gašper Ažman <gasper.azman_at_[hidden]>
Date: Thu, 17 Aug 2023 09:41:04 +0100
Yes, what Lénárd said, unless you actually need to treat it as a
std::array, in which case I'm still interested in the answer to my question.


On Thu, Aug 17, 2023, 09:27 Lénárd Szolnoki via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Thu, 2023-08-17 at 09:12 +0100, Frederick Virchanza Gotham via Std-
> Proposals wrote:
> > On Wed, Aug 16, 2023 at 11:08 PM Jason McKesson wrote:
> > > >
> > > > std::array arr = {
> > > > something1,
> > > > something2,
> > > > something3,
> > > > };
> > > >
> > > > also works.
> > >
> > > That deduction guide has been there since C++17, so it's standard.
> > > Assuming of course that all of those are of the same type.
> >
> >
> > I'm looking through cppreference.com here and I don't see a function
> > something like:
> >
> > template< typename T, std::size_t len >
> > std::array<T,len> &pretend_is_std_array( T (&arg)[len] ); //
> > returns
> > a reference
> >
> > What are we supposed to do if we want to treat a C-style array as
> > though it's an std::array? Should we just reinterpret_cast?
>
> No, use std::span. C arrays, std::array and even std::vector and
> subranges of these are compatible with std::span.
>
> Or if you are writing a template then use contiguous_range, if you have
> to make use of contiguity.
>
> Cheers,
> Lénárd
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-08-17 08:41:17