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:27:13 +0100
That's up to the pointer interconvertibility rules. If I squint it seems to
be permitted? Not sure if I'm forgetting another rule.

https://en.cppreference.com/w/cpp/types/is_pointer_interconvertible_with_class

However, you'd need to somehow get the inner array pointer as a pointer to
member...

On Thu, Aug 17, 2023, 09:12 Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> 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?
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-08-17 08:27:28