Topic: `box` - A container which may hold exactly zero or
Author: Nicole Mazzuca <npmazzuca@gmail.com>
Date: Mon, 4 Jun 2018 23:19:27 -0700 (PDT)
Raw View
------=_Part_38444_411294902.1528179567438
Content-Type: multipart/alternative;
boundary="----=_Part_38445_752087363.1528179567438"
------=_Part_38445_752087363.1528179567438
Content-Type: text/plain; charset="UTF-8"
I've often wished for a container that can hold exactly one object -
something
like `std::unique_ptr`, but with value and container semantics. I want deep
compare, deep copy, etc. However, there isn't any container that fits the
bill
in the current standard library. I'd like to gauge interest in having a type
like this.
I've called it `box`, because that's often how these things are referred to
-
Rust has `Box<T>`, Racket has `box`, Java has "Boxing". The name is
completely
up for bikeshedding. The interface is on my github, here:
https://github.com/ubsan/ublib/blob/master/box/include/ublib/box.h#L50
The sample implementation of the member functions is here:
https://github.com/ubsan/ublib/blob/master/box/include/ublib/__box_impl.h
I apologize for the mostly untested code, as well as any weird things that
clang-format may have done! At this point, it's just a proof of concept.
However, that is intended to be the "final" interface, so if there's
anything in
there you object to, or anything you'd like to see added, please speak up!
I'm not certain this would be good for standardization, which is why I've
placed
it in the `ublib` namespace. I think, personally, it would be very useful
for
things like recursive types, as well as whenever one wants to put something
behind a pointer, for whatever reason. `std::unique_ptr` is a useful tool,
but
it's fairly poor when one wants a proper C++ container type.
Some notes:
First - I'm not sure whether `reverse_iterator` should be a
`std::reverse_iterator` - it works just fine as a normal `iterator`, given
that
there can either be zero or one elements, and a reversed range of zero or
one
elements is the same range. I felt as though `rbegin` and the like should be
provided, however, as there's no reason not to have them.
Second - This doesn't follow the requirements for AllocatorAwareContainer -
it's
a Container, which is aware of allocators, but it uses the new
`std::allocator_arg_t` style interface.
Third - Comparison is a lexicographic comparison.
And I think that's it! If you have any questions, please ask away!
Thanks for your time,
Nicole Mazzuca
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f111e16b-4ab0-4f98-899a-f58133223ccc%40isocpp.org.
------=_Part_38445_752087363.1528179567438
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I've often wished for a container that can hold exactl=
y one object - something<br>like `std::unique_ptr`, but with value and cont=
ainer semantics. I want deep<br>compare, deep copy, etc. However, there isn=
't any container that fits the bill<br>in the current standard library.=
I'd like to gauge interest in having a type<br>like this.<br><br>I'=
;ve called it `box`, because that's often how these things are referred=
to -<br>Rust has `Box<T>`, Racket has `box`, Java has "Boxing&q=
uot;. The name is completely<br>up for bikeshedding. The interface is on my=
github, here:<br><br>https://github.com/ubsan/ublib/blob/master/box/includ=
e/ublib/box.h#L50<br><br>The sample implementation of the member functions =
is here:<br><br>https://github.com/ubsan/ublib/blob/master/box/include/ubli=
b/__box_impl.h<br><br>I apologize for the mostly untested code, as well as =
any weird things that<br>clang-format may have done! At this point, it'=
s just a proof of concept.<br>However, that is intended to be the "fin=
al" interface, so if there's anything in<br>there you object to, o=
r anything you'd like to see added, please speak up!<br><br>I'm not=
certain this would be good for standardization, which is why I've plac=
ed<br>it in the `ublib` namespace. I think, personally, it would be very us=
eful for<br>things like recursive types, as well as whenever one wants to p=
ut something<br>behind a pointer, for whatever reason. `std::unique_ptr` is=
a useful tool, but<br>it's fairly poor when one wants a proper C++ con=
tainer type.<br><br>Some notes:<br><br>First - I'm not sure whether `re=
verse_iterator` should be a<br>`std::reverse_iterator` - it works just fine=
as a normal `iterator`, given that<br>there can either be zero or one elem=
ents, and a reversed range of zero or one<br>elements is the same range. I =
felt as though `rbegin` and the like should be<br>provided, however, as the=
re's no reason not to have them.<br><br>Second - This doesn't follo=
w the requirements for AllocatorAwareContainer - it's<br>a Container, w=
hich is aware of allocators, but it uses the new<br>`std::allocator_arg_t` =
style interface.<br><br>Third - Comparison is a lexicographic comparison.<b=
r><br>And I think that's it! If you have any questions, please ask away=
!<br><br>Thanks for your time,<br><br>Nicole Mazzuca<br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f111e16b-4ab0-4f98-899a-f58133223ccc%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f111e16b-4ab0-4f98-899a-f58133223ccc=
%40isocpp.org</a>.<br />
------=_Part_38445_752087363.1528179567438--
------=_Part_38444_411294902.1528179567438--
.