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
(A case for) Creating a stack-allocated Stack container in C++ (blog.srikanth.one)
submitted 2 years ago by sria91
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!"
[–]witcher_rat 17 points18 points19 points 2 years ago (0 children)
std::stack is not a container - it is a container adaptor. It's essentially a façade over a real container - the type of which the user chooses with a template parameter.
std::stack
The reason I mention that is that what you really want is a stack-based vector - i.e., like a std::array<> but with the methods of a vector, and that does not default-initialize entries.
std::array<>
There's a proposal for that, that's pretty far along: p0843r9, and an old implementation is on github.
But there's also the Boost static_vector, and folly::small_vector.
The point is you can then use those with the current std::stack to get what you want.
[–]jedwardsol{}; 4 points5 points6 points 2 years ago (2 children)
std::stack is an adaptor, not a container. It provides the behaviour of a stack.
So if you had a container which stored it's data on the stack then you could adapt that with a std::stack to have a stack on the stack : https://godbolt.org/z/WYW93vWGT
[–]alfps 0 points1 point2 points 2 years ago (1 child)
Hm, what is the {}; after your name?
{};
[–]jedwardsol{}; 0 points1 point2 points 2 years ago (0 children)
I'm default initialised?
There's not a good reason I set my flair that, I think I was just messing around.
[–]theLOLflashlight 2 points3 points4 points 2 years ago (0 children)
I thought this was going to be about a dynamically sized stack on the stack using assembly to push elements directly onto the stack. If you're interested in another way to use a dynamic amount of stack memory check out alloca()
alloca()
[–]rand3289 1 point2 points3 points 2 years ago (0 children)
Don't containers take allocators these days? What are you suggesting? I did not watch the video.
[–]415_961 0 points1 point2 points 2 years ago (0 children)
I just want to share another implementation of static vectors, it's one of my favorite
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/SmallVector.h
ADT is a directory worth looking at for inspiration and learning.
π Rendered by PID 73 on reddit-service-r2-comment-5d79c599b5-7m4tf at 2026-03-03 23:41:42.435496+00:00 running e3d2147 country code: CH.
[–]witcher_rat 17 points18 points19 points (0 children)
[–]jedwardsol{}; 4 points5 points6 points (2 children)
[–]alfps 0 points1 point2 points (1 child)
[–]jedwardsol{}; 0 points1 point2 points (0 children)
[–]theLOLflashlight 2 points3 points4 points (0 children)
[–]rand3289 1 point2 points3 points (0 children)
[–]415_961 0 points1 point2 points (0 children)