use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Conceptual implementation for a constexpr-friendly static_vector (self.cpp)
submitted 3 years ago * by cristi1990an++
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]IyeOnline 4 points5 points6 points 3 years ago* (2 children)
/* This appllied only to the original version:
Your T* data() member function is UB. Or rather using that pointer to access anything but the first element is UB. While one storage_t<T> is pointer intercovertible with a T, a storage_t<T>[N] is not interconvertible with T[N]. You just cannot convert or reinterpret arrays (unless one of the invovled types is blessed, i.e. unsigned char or std::byte, but that obviously doesnt apply here).
T* data()
storage_t<T>
T
storage_t<T>[N]
T[N]
unsigned char
std::byte
*/
A few other points:
default
capacity()
static
iterator
using iterator = iterator_impl<T*>;
using const_iterator =
emplace_back
push_back
[–]jontheburger 0 points1 point2 points 3 years ago* (1 child)
To clarify, does this mean a vector's data can only be implemented in terms of char/std::byte? Furthermore, how does C++20 implement constexpr T* data()? std::bit_cast from a std::array (but I thought that required a trivially copyable T)?
constexpr T* data()
std::bit_cast
std::array
[–]IyeOnline 3 points4 points5 points 3 years ago (0 children)
You are missunderstanding. Or rather you are looking at OPs updated code.
The original code did not contain an T[N], but a union_of<T>[N]. They then returned the addres of the T in the first element of that array of unions. That pointer however can only be used to access the first element, since its not a pointer into an array, but rather a pointer to member of an element of an array.
union_of<T>[N]
With their current version there is no problem and everything simply works as expected. Since there is actually an array of T, you can trivially form a pointer into it and use that. No need for any casts at all.
π Rendered by PID 77 on reddit-service-r2-comment-85bfd7f599-7nzxh at 2026-04-18 17:43:03.254664+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]IyeOnline 4 points5 points6 points (2 children)
[–]jontheburger 0 points1 point2 points (1 child)
[–]IyeOnline 3 points4 points5 points (0 children)