Answer by HolyBlackCat for how to know an enum class is sorted
There's no way to check the declaration order. Best you can do is check that the constants are contiguous (i.e. there are no gaps in the numbering).First you start with __PRETTY_FUNCTION__/__FUNSIG__....
View ArticleComment by HolyBlackCat on Recommendation project for school
Tell your prof that those defines should be usings.
View ArticleComment by HolyBlackCat on How do you get cabal to look in `/usr/include` for...
Does this answer your question? What are MSYS2 environments? How do I pick one?
View ArticleAnswer by HolyBlackCat for Can NRVO and Move Semantics Be Used Together in C++?
If you were to do std::vector<std::string> v = createAndInsert();, first there would be a move from coll to the returned temporary (NRVO may or may not elide it), then another move from that...
View ArticleComment by HolyBlackCat on SDL compiling error using g++ undefined reference...
@Someprogrammerdude You do need -lmingw32 for SDL2. (It has something to do with linking order, IIRC because -lSDL2main provides its own main or WinMain, and -lmingw32 doesn't find it with default link...
View ArticleComment by HolyBlackCat on Create STL array of struct with const class member
Const and reference class members are annoying in general. You should rather make the whole object const, not the individual members.
View ArticleComment by HolyBlackCat on How compiler was made (GCC or Clang)
Here's how you can bootstrap GCC from no compiler in modern times: stackoverflow.com/a/65708958/2752075
View ArticleComment by HolyBlackCat on For loop: signed / unsigned integer expression...
Just don't use unsigned types (except for bit manipulation). They don't help prevent any errors (what would be an invalid negative value is now an invalid large value).
View ArticleComment by HolyBlackCat on Is padding important when calling to placement new?
I don't think it's allowed to touch the padding, since the struct is trivially-constructible. But it may or may not be formally UB, I'm not sure (probably harmless in practice). I'm more worried about...
View ArticleAnswer by HolyBlackCat for How to abort makefile if variable not set?
Another option:MY_FLAG = $(error Please set this flag)Attempting to use this variable anywhere will cause an error, unless it's overriden from the command line.To accept environment variables as well,...
View ArticleAnswer by HolyBlackCat for To evaluate constant in run time via function c++17
Using a function doesn't require moving evaluation to runtime. Just add constexpr to the function and it will work at compile-time.const float _MOVEMENT_ = deg_to_rad(90); will work even without a...
View ArticleComment by HolyBlackCat on "Exception thrown: write access violation. this...
#define SDL_MAIN_HANDLED#define main SDL_main Ouch. The two cancel out, you can remove both.
View ArticleComment by HolyBlackCat on What do C++ for-range loops expand to?
The first snippet is not entirely correct, it doesn't handle continue; properly. "from testing that is not entirely the same"cppreference has a better version. Where did you get yours from?
View ArticleComment by HolyBlackCat on How to cast my custom shared pointer in C++
You need T* to be directly in SharedPtr, not next to the ref counter. Because when multiple inheritance is involved, after a pointer cast you can have a pointer with the same ref counter pointer, but a...
View ArticleComment by HolyBlackCat on Why is iter_const_reference_t not simply using...
std::add_const_t<T &> is just T &, you need to remove the reference before applying it. But that probably isn't good enough either, because iter_reference_t doesn't have to be an actual...
View ArticleComment by HolyBlackCat on Why does a function taking a std::unique_ptr by...
The caller destroys the parameter. I'll tell you more, the parameter (in GCC & Clang at least) seems to live until the end of the full expression calling the function.
View ArticleComment by HolyBlackCat on -O3 optimisation in C++ causing disk write...
Try to build with -static.
View ArticleAnswer by HolyBlackCat for C++20 std::vector comparison weird behaviour
C++20 replaces the individual <,<=,>,>= operators of std::vector (and of many other standard classes) with a single <=>.Internally it tries to use <=> to compare the elements,...
View ArticleAnswer by HolyBlackCat for Why creating the same class object allowed inside...
(2) fails because the class it not complete yet at that point (the full list of member variables isn't known yet, more or less). And also because of common sense, as it would cause an infinite nesting...
View ArticleComment by HolyBlackCat on A strange thing about vector under multi-thread...
@Fareanor You meant value-initialized.
View Article