martinmoene / ring-span-lite

ring-span lite - A C++yy-like ring_span type for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
152 stars 12 forks source link

`nonstd::ring` with a fixed array type as the container #33

Closed Crzyrndm closed 4 months ago

Crzyrndm commented 4 months ago

ring type here being the owning buffer that wraps a container and a ring_span. Right now the ring type is unable to use a fixed size array as the backing container because the only constructor requires a capacity argument https://github.com/martinmoene/ring-span-lite/blob/master/include/nonstd/ring.hpp#L51-L54

all that is required to support ring<std::array<T, N>> is conditionally adding a default ctor (I've made it conditional on not having a with_capacity ctor here) https://github.com/Crzyrndm/ring-span-lite/blob/array-ctor/include/nonstd/ring.hpp#L52-L56 Built in / C array support would probably only require changing.begin()/end()tostd::begin/end`

Not sure if that's the right condition to use but it's working for the moment

Quuxplusone commented 4 months ago

I have no meaningful opinion on the actual feature request, but I'll just leave this here: std::is_constructible_v<int[10], size_t> is true in C++20, because of paren-agg-init. https://quuxplusone.github.io/blog/2022/06/03/aggregate-parens-init-considered-kinda-bad/

martinmoene commented 4 months ago

@Crzyrndm Thanks for the heads-up.

Enabling the use of a C-array as template parameters requires some more work.

martinmoene commented 4 months ago

@Crzyrndm C-array and std::array are now supported as the backing container.

So now one can write:

nonstd::ring< int[3] > r;
nonstd::ring< std::array<int, 3 >> s;
martinmoene commented 4 months ago

Completed.