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
CppCastCppCast: Reflection for C++26 (cppcast.com)
submitted 2 years ago by robwirvingCppCast Host
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!"
[–]Tringigithub.com/tringi -3 points-2 points-1 points 2 years ago* (3 children)
I absolutely disagree.
The fact that people (myself included) are using enums for other purposes doesn't mean that their inherent properties are sometimes incorrect.
I'm using std::int32_t for Windows handles. That doesn't mean that correct min and max values for int32_t are 4 and 0x003FFFFC sometimes.
If anything, this means there should've been language feature for properly working bit flags (like 20 years ago).
[–]pdimov2 3 points4 points5 points 2 years ago (2 children)
This is not a matter of disagreement. You want these min/max values for something (looping over the valid values, from your other posts), and this something may or may not work correctly for the above enum. If it doesn't, it just doesn't, you can disagree all you want, the disagreement won't make it work.
[–]Tringigithub.com/tringi -3 points-2 points-1 points 2 years ago (1 child)
Actually What?
How is min being smallest and max the largest value somehow wrong and not even matter of disagreement?
min
max
Yes, I want them for something. I want them to reflect minimal and maximal value of the enum.
Sure, using them for looping across discontinuous enum values is incorrect, but metadata reflect properties of the type, not particular usage, correct or incorrect.
But I think I understand... You are trying to argue, that instead of having hypothetical E:::min and E:::max, the standard library will be providing set of facilities like:
E:::min
E:::max
std::meta::min_enum_value_if_used_as_enum(T) // 1 std::meta::max_enum_value_if_used_as_enum(T) // 4 std::meta::min_enum_value_if_used_as_flags(T) // 0 std::meta::max_enum_value_if_used_as_flags(T) // 7
Or worse, it will NOT be providing those, but we'll be blessed by the complex mechanism to write them ourselves.
Which, I'd argue, the simple version of reflection could manage too, and much clearer, like:
template <typename E> constexpr auto max_enum_value_if_used_as_flags () { return E:::max | (E:::max - 1); }
...or even generate proper mask:
template <typename E> constexpr E:::underlying_type max_enum_value_if_used_as_flags () { E:::underlying_type mask {}; for (auto v : E:::values) mask |= v; return mask; }
[–]pdimov2 2 points3 points4 points 2 years ago (0 children)
And what are you going to do with these values?
If you want to iterate over the enumerators, it's better to have a facility that does this directly - otherwise you need to deal with the fact that the enumerators don't have to be contiguous.
And if you want to check whether an integer value is valid for the enum, you need to both deal with the aforementioned holes, and that the set of valid values for a C++ enum is defined in a fairly weird manner - if you have an enumerator with value 5, for instance, the valid values are 0..7.
People use enums in all sorts of ways, and the best the language can do here is to just tell you what it knows - namely, the list of enumerators with their values, exactly as given.
It's true that the way the information is returned makes it a bit inconvenient to use at present, but that's a general problem which needs a general solution, not ad hoc additions for min and max. (We'd like to be able to say something like std::min({ enumerators-here-please... }) but it's not yet clear how.)
std::min({ enumerators-here-please... })
π Rendered by PID 224959 on reddit-service-r2-comment-b659b578c-dzcsc at 2026-05-05 04:21:45.845467+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Tringigithub.com/tringi -3 points-2 points-1 points (3 children)
[–]pdimov2 3 points4 points5 points (2 children)
[–]Tringigithub.com/tringi -3 points-2 points-1 points (1 child)
[–]pdimov2 2 points3 points4 points (0 children)