Array design sketch #1061
geoffromer
started this conversation in
General
Replies: 2 comments 6 replies
-
Why is |
Beta Was this translation helpful? Give feedback.
6 replies
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm starting to sketch out a proposal for arrays and slices. Here's what I have in mind:
StaticArray(T, N)
is basically equivalent tostd::array<T, N>
, except that it's the fundamental fixed-size array type, not a library wrapper for something else.BoxedArray(T)
is roughly equivalent tostd::unique_ptr<T[]>
: provides the API of an array whose size is fixed when the array is created (i.e. at run-time), and is implemented in terms of a single uniquely-owned pointer.RuntimeSizedArray(T)
is what that pointer points to: an array whose size is fixed when the array is created (i.e. at run-time). It has no standard C++ counterpart, but it's somewhat comparable to a C variable-length array or flexible array member. It's an unsized type, which will make it awkward to work with, so I expect people to useBoxedArray(T)
unless they specifically need to avoid the indirection and/or the ownership semantics.Resizable arrays and other pure library types are out of scope (
BoxedArray
is a pure library type, but I'm including it becauseRuntimeSizedArray
would look kind of alarming on its own).These types will all support subscripting with
i64
, and haveLength
andSlice
methods. I expect them to eventually support iteration, equality comparison, ordering, and hashing, but we don't have interface designs for those yet. We might also want to define anArray(T)
interface expressing all that, but I'm not sure whether that will be useful.They will all support initialization from a tuple of the appropriate size, if the tuple element types are all convertible to
T
.Slice(T)
is basically equivalent tostd::span<T>
. It supports all the same operations as the array types except for equality, ordering, and hashing (which I'd like to leave as future work because they're an utter minefield), and also supports assignment.Names are all subject to bikeshedding, and we may want to have a more concise and/or "built-in feeling" type syntax for
Slice
,StaticArray
, and perhapsBoxedArray
, but I don't plan to include that in the initial proposal.The proposal won't cover multidimensionality because we don't have a design for variadics yet, and because I'm undecided about whether to use these types for the multidimensional case (where things like
Length
and iteration get awkward), or have a separate family of types for that.Any thoughts on whether this sounds like the right general direction?
Beta Was this translation helpful? Give feedback.
All reactions