[libcxx-commits] [PATCH] D140259: [libc++] Add __small_buffer
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 19 11:21:30 PST 2022
ldionne accepted this revision.
ldionne added inline comments.
================
Comment at: libcxx/include/__utility/small_buffer.h:25-28
+// __small_buffer helper for type-erasing classes like move_only_function to store small objects in a local buffer.
+// Only objects that are trivially relocatable can be stored inside it to allow __small_buffer to be trivially
+// relocatable itself. Since the buffer doesn't know what's stored inside it, the user has to manage the object's
+// lifetime, in particular the destruction of the object.
----------------
================
Comment at: libcxx/include/__utility/small_buffer.h:38-43
+ template <class _Tp>
+ static constexpr bool __fits_in_buffer = [] {
+ using _DTp = decay_t<_Tp>;
+ return is_trivially_move_constructible_v<_DTp> && is_trivially_destructible_v<_DTp> &&
+ sizeof(_DTp) <= _BufferSize && alignof(_DTp) <= _BufferAlignment;
+ }();
----------------
This avoids instantiating a lambda and it's pretty easy to do, so we might as well.
================
Comment at: libcxx/include/__utility/small_buffer.h:45-52
+ __small_buffer() = default;
+ __small_buffer(const __small_buffer&) = delete;
+ __small_buffer& operator=(const __small_buffer&) = delete;
+ ~__small_buffer() = default;
+
+ // Relocates the buffer - __delete() should never be called on a moved-from __small_buffer
+ __small_buffer(__small_buffer&&) = default;
----------------
I think the `= default` ones should be `_LIBCPP_HIDE_FROM_ABI`, since they *are* generated at the end of the day.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140259/new/
https://reviews.llvm.org/D140259
More information about the libcxx-commits
mailing list