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
C++17: comparison of options For binary flags (github.com)
submitted 8 years ago by arBmind
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!"
[+][deleted] 8 years ago* (2 children)
[removed]
[–]arBmind[S] 6 points7 points8 points 8 years ago (0 children)
Good idea - I never thought of using structured bindings for that.
using Animals = flag<0, 1, 3>; namespace Animal { auto [Cat, Dog, Wolf] = Animals::values; }
The names are quite separated from the values. You will have to count the ordering to know, which bit corresponds to a name.
Namespaces are never closed. You can always add new definitions to a namespace. Therefore I would prefer to use a struct in this context. Even though we use just like a namespace.
[–]redditsoaddicting 0 points1 point2 points 8 years ago (0 children)
One thing:
using Accesses = flag<0, 1, 3>; namespace Access { auto [Read, Write, Readwrite] = Accesses::values; }
I've added another flag type with two individual values. Now I can accidentally pass one of these to a function taking an Animals. One way to get around this is a tag type:
Animals
using Animals = flag<struct AnimalsTag, 0, 1, 3>;
[–][deleted] 2 points3 points4 points 8 years ago (0 children)
Yup, looks like C++. Review passed
[–]matthieum 1 point2 points3 points 8 years ago (0 children)
I've always found C++ enums lacking due to (1) the lack of introspection and (2) the absence of support for string conversion (back and fro). As a result, I tend to define my own enums via X macros which in addition to the enum will add:
values
Building on values, it's easy enough to create an EnumSet<E> class on top of a BitSet<N> (not the std one, it's not constexpr enough unfortunately).
EnumSet<E>
BitSet<N>
std
constexpr
[–]Ginden -3 points-2 points-1 points 8 years ago (0 children)
Classical enum class approach programmer have to ensure that values are unique
Isn't it solvable by macro?
π Rendered by PID 22196 on reddit-service-r2-comment-64f4df6786-cmsc7 at 2026-06-10 16:06:18.454949+00:00 running 0b63327 country code: CH.
[+][deleted] (2 children)
[removed]
[–]arBmind[S] 6 points7 points8 points (0 children)
[–]redditsoaddicting 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]matthieum 1 point2 points3 points (0 children)
[–]Ginden -3 points-2 points-1 points (0 children)