Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how about not use this char array storage, it lose type info, is not easy to debug #4

Open
tycable opened this issue Apr 28, 2023 · 1 comment

Comments

@tycable
Copy link

tycable commented Apr 28, 2023

alignas(alignof(T)) unsigned char storage[sizeof(T)];

@DanielLiamAnderson
Copy link
Contributor

That's a reasonable point. The member can not just be an ordinary T object since we need to be able to manually control the construction and destruction. The two main ways to achieve this are either:

  1. using an aligned char array (here)
  2. by using a single-member union, i.e., union { T value; }

The union member acts like an ordinary member except that we are responsible for manually constructing and destructing it. When I last looked at libc++, libstdc++, and Microsoft STL's implementation of std::shared_ptr, both of these techniques were used by at least one of them, so neither seems strictly preferred. The union would be easier to debug though, so we could switch to that.

If you want to Pull Request that change I'll take it. Otherwise I can do it myself at some point, but it might be a bit later since I am busy right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants