Conversion to/from std types #263
Labels
design
Design of the library systems as a whole, such as concepts
std-compat
Compatibility with std library types or concepts
Milestone
unique_ptr<DynError>
? And strings?References?
The tricky thing is when we have a reference type in the sus type.
Option<T&>
can convert tooptional<T*>
, butoptional<T*>
will convert toOption<T*>
.Option<T&>
convert tooptional<T>
?Result<T&, E>
.Vec
For
Vec
, we can't construct astd::vector
with a pointer of our choosing, or rip the pointer out of it. So proposing that instead ofVec<T, Allocator>
we haveVec<T, Driver>
.The
Driver
will provide theAllocator
but it will also provide an abstract API that can choose how to store theVec
's data. Then we provide two Drivers:VecDriver
which uses theSlice
pointers in theVec
in-place to manage the memory (this is how the code is written today). The VecDriver is an empty class so it does not contribute to Vec's size at all.StdDriver
which stores astd::vector
inside it, and then mirrors thestd::vector
's pointers into theVec
'sSlice
pointers.What this means is we can construct a
Vec<T, StdDriver<T>>
from astd::vector
with just a (cheap) move of thestd::vector
, and we can unwrap theVec<T, StdDriver<T>>
back into astd::vector<T>
as well. TheVec
with aStdDriver
is necessarily larger, unless we commit ABI crimes and just read/write from thestd::vector
as achar
array. That is another possible Driver option though.Converting between
Vec<T, StdDriver<T>>
andstd::vector<T>
would be ~the same as a move ofstd::vector<T>
. Whereas converting betweenVec<T>
andstd::vector<T>
will require an allocation and a move of each item between buffers.Because allocators are also a thing, the Driver would have an optional Allocator type parameter, so technically its
Vec<T, Driver<Allocator>>
.The text was updated successfully, but these errors were encountered: