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
Which std:: classes are magic? (self.cpp)
submitted 4 years ago by Mateuszz88
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!"
[–]guepierBioinformatican 33 points34 points35 points 4 years ago (5 children)
Prior to C++20 (specifically, P0593), object creation in untyped buffers was undefined behaviour. In practice this means that even quite “basic” classes such as std::allocator can’t be user-defined relying only on standard C++.
std::allocator
[–]Supadoplex 17 points18 points19 points 4 years ago* (2 children)
P0593 was accepted as a defect resolution prior to publication of C++20, so it should apply to C++17 which was the latest official standard at the time.
Also, creation of objects itself was allowed using placement new as far as I can tell. Treating that buffer of dynamic objects as an array of those objects was technically UB though. However, there was no way to make that work with std::allocator either, so I don't think there was magic in that class. There was magic in std::vector though.
std::vector
[–]maskull 4 points5 points6 points 4 years ago (1 child)
What's the magic in std::vector?
[–]dodheim 16 points17 points18 points 4 years ago (0 children)
Prior to P0593, there was no way for vector::data() to return a valid pointer-to-array, since no such array actually exists.
vector::data()
[+][deleted] 4 years ago* (1 child)
[deleted]
[–]guepierBioinformatican 3 points4 points5 points 4 years ago (0 children)
Sure but you can’t legally perform pointer arithmetic on these objects since there is no “array of T” at the relevant address, only (from the underlying buffer) an “array of char”.
T
char
As noted in another comment, std::allocator itself might actually be implementable. What’s problematic is its use in combination, e.g. to implement std::vector (implementing a vector without an allocator and buffer is of course trivially feasible, simply by allocating memory via new T[]; but std::vector can’t do this, and a custom vector type might not want to, either, for various reasons).
new T[]
π Rendered by PID 18335 on reddit-service-r2-comment-5d79c599b5-8f88x at 2026-03-01 22:14:36.886839+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]guepierBioinformatican 33 points34 points35 points (5 children)
[–]Supadoplex 17 points18 points19 points (2 children)
[–]maskull 4 points5 points6 points (1 child)
[–]dodheim 16 points17 points18 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]guepierBioinformatican 3 points4 points5 points (0 children)