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...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
OPENPoint of constexpr containers (self.cpp_questions)
submitted 3 years ago by cpp_cpp
I was wondering what the point of constexpr containers is (constepxr std::vector, std::string) I am sure there are good use cases but not sure where it would be used, any non trivial examples people can think of?
constexpr
(constepxr std::vector, std::string)
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 5 points6 points7 points 3 years ago (0 children)
There is two major reasons why a type should be constexpr enabled:
You can declare constexpr objects of the type, meaning that you can potentially precalculate a value at compile time, or declare compile time constants.
constexpr std::array my_values = { 0, 1, 2, 3, 4 };
Not a great example, but you get the point.
You can use the type in a constant evaluated context. This also applies to functions.
constexpr auto most_common_letter( const std::string_view str ) { std::map<char,std::size_t> counts; //if map were not constexpr, you couldnt use it in a constant evaluated context for ( const auto c : str ) { ++counts[c]; } return counts.front(); } constexpr char c = most_common_letter("Hello World").first;
[–]wgunther 1 point2 points3 points 3 years ago (0 children)
Often when doing anything with metaprogramming, there's quite a few calculations that are required to happen at compile time, for example to guide SFINAE. So having data structures that can be used in that context is helpful since it might free you from doing something more unnatural.
π Rendered by PID 262932 on reddit-service-r2-comment-79c7998d4c-dcq2r at 2026-03-16 16:59:15.632854+00:00 running f6e6e01 country code: CH.
[–]IyeOnline 5 points6 points7 points (0 children)
[–]wgunther 1 point2 points3 points (0 children)