bit_blast: update cxx_enums
BIN
youtube/video_series/bit_blast/cxx_enums/compiler explorer.png
Normal file
After Width: | Height: | Size: 337 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 55 KiB |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 69 KiB |
63
youtube/video_series/bit_blast/cxx_enums/description.md
Normal file
|
@ -0,0 +1,63 @@
|
|||
< INSERT VIDEO DESCRIPTION >
|
||||
|
||||
*//=======================[ Code Snippets ]=======================//*
|
||||
_Unscoped Declaration_: https://godbolt.org/z/9MosoovPP
|
||||
_Scoped Declaration_: https://godbolt.org/z/oT5TbP6vx
|
||||
_Anonymous Declaration_: https://godbolt.org/z/s97n5jETs
|
||||
_Scoped vs Unscoped_: https://godbolt.org/z/h65cjMEhb
|
||||
_Explicit Underlying Type_: https://godbolt.org/z/ehY7Gns6E
|
||||
_Default Case_: https://godbolt.org/z/a6KWE8b4c
|
||||
_Utilize Zero_: https://godbolt.org/z/fvE6z9jMf
|
||||
_Utilize Counting_: https://godbolt.org/z/5EEhYrcr9
|
||||
_Using Enum Syntax_: https://godbolt.org/z/shaE6Yc64
|
||||
_Bitfield Operators_: https://godbolt.org/z/acMW45K9o
|
||||
_Standard Utilities_: https://godbolt.org/z/9xKcxEsP5
|
||||
|
||||
*//============================[ Sources ]============================//*
|
||||
_cppreference_: https://en.cppreference.com/w/cpp/language/enum.html
|
||||
|
||||
Proposal Papers:
|
||||
_N2347 — Strongly Typed Enums_: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf
|
||||
_N3815 — Enumerator List Property Queries_:https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3815.html
|
||||
_N4196 — Attributes for namespaces and enumerators_: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4196.html
|
||||
_P0138R2 — Construction Rules for enum class Values_: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0138r2.pdf
|
||||
_P1682R3 — std::to_underlying for enumerations_: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1682r3.html
|
||||
_P1099R5 — Using Enum_: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1099r2.html
|
||||
|
||||
*//========================[ Forge & Mirrors ]========================//*
|
||||
_Forge_: https://forge.light7734.com/light7734 | https://git.light7734.com/light7734
|
||||
_Github Mirrors: https://github.com/light7734
|
||||
_Gitlab Mirrors: https://gitlab.com/light7734
|
||||
_Codeberg Mirrors: https://codeberg.org/light7734
|
||||
|
||||
*//============================[ Socials ]============================//*
|
||||
**Matrix Community**: https://matrix.to/#/#hELL:matrix.org
|
||||
**Discord Community**: https://discord.gg/N3AJJG2tGF
|
||||
**Matrix**: @light7734:matrix.org
|
||||
**Discord**: @light7734
|
||||
**Mail**: mail@light7734.com
|
||||
**YouTube**: https://www.youtube.com/@light.7734
|
||||
**XTwitter**: https://x.com/light7734
|
||||
**BlueSky**: https://bsky.app/profile/light7734.bsky.social
|
||||
**Reddit** (currently suspended...): https://www.reddit.com/user/Light7734/
|
||||
**Steam** (don't judge me): https://steamcommunity.com/id/light7734/
|
||||
**Itch.io**: https://light7734.itch.io/
|
||||
|
||||
*//========================[ Software I Use ]========================//*
|
||||
_OS_: Arch Linux x86-64
|
||||
_Shell_: Zsh
|
||||
_DE/WM_: Gnome/XMonad
|
||||
_Terminal_: Kitty
|
||||
_Colorscheme_: Gruvbox
|
||||
_Font_: JetbrainsMono Nerd Font
|
||||
|
||||
_Code Editor_: Neovim
|
||||
_Image Editor_: GIMP
|
||||
_Video Editor_: Kdenlive
|
||||
|
||||
_3D Art_: Blender
|
||||
_Pixel Art_: Aseprite
|
||||
_Digial Art_: Krita
|
||||
_Vector Art_: Inkscape
|
||||
|
||||
_DAW_: FL Studio 24 (on Windows, with support of flchan ofc)
|
|
@ -1,4 +1,8 @@
|
|||
# Hook
|
||||
---
|
||||
title: BitBlast | The Cooked State of Enums
|
||||
---
|
||||
|
||||
# Hook <20s
|
||||
"There should be one, and preferably only one, obvious way to do it." --- The Zen of Python
|
||||
A principle which C++ defies in many fronts, enums being one of them,
|
||||
assuming you know the basics, let's learn more about enums!
|
||||
|
@ -17,8 +21,8 @@ There are mainly 3 ways we could declare one.
|
|||
|
||||
3: The anonymous enum
|
||||
-> Much like the classic enum, but without a qualifier
|
||||
-> It was used as a way of storing constants before constexprs were a thing
|
||||
-> There's a neat trick you coud do with anonymous or unscoped enums, and that is to put it inside a namespace and have the middle-ground of scoped and unscoped enums
|
||||
-> It was used as a way of storing constants
|
||||
-> But there's also a neat trick you could do with anonymous or unscoped enums, and that is to put it inside a namespace and have the middle-ground of scoped and unscoped enums
|
||||
-> It allows implicit conversion to integer types.
|
||||
-> But, it still requires proper qualification when accessing its elements. And won't pollute the enclosing namespace.
|
||||
|
||||
|
@ -41,10 +45,10 @@ Like this! always do this, even if the type is int--- It serves as documentation
|
|||
3: Avoid the "default" Case
|
||||
This may be too much in certain cases, but try to develop a preference for explicitly handling all enums values.
|
||||
Even if multiple values execute the same code, you could fall-through them if you don't put breaks in-between.
|
||||
You could enable warnings as errors for catching incomplete switch statements.
|
||||
You could enable warnings as errors for catching incomplete statements.
|
||||
So when you inevitably add new values to your enums, the compiler will have your back.
|
||||
|
||||
4: Utilize [Dio: ZERO]
|
||||
4: Utilize Zero
|
||||
Since zero evaluates to false, and other values to true, you could treat it as a special value for making a binary decision.
|
||||
For example, in Vulkan API, the VkResult has 0 for success, and errors are set to non-zero values.
|
||||
This makes the decision to handle-error or move-on a binary decision like this.
|
||||
|
@ -52,11 +56,18 @@ This makes the decision to handle-error or move-on a binary decision like this.
|
|||
5: Utilize Its Counting Nature
|
||||
The values are implicitly incremented, this means you could have a "count" element at the end like so.
|
||||
|
||||
6: (Are you using it as a) Bitfield? (Then consider) Overload(ing) the Bitwise Operators.
|
||||
6: Using enum
|
||||
Remember how namespaced anonymous or unscoped enums enforced explicit qualification, yet allowed implicit conversion?
|
||||
We could have it the other way around with the using enum syntax.
|
||||
This way explicit qualification is not required, but implicit conversion is still prohibited.
|
||||
|
||||
7: (Are you using it as a) Bitfield? (Then consider) Overload(ing) the Bitwise Operators.
|
||||
|
||||
8: Std Utilities
|
||||
And to wrap it up.. here are some enum utilities from the standard library...
|
||||
|
||||
Now, the best way to learn is to experiment,
|
||||
You can find compiler explorer links for all the code you've seen in this video in the description.
|
||||
|
||||
If you want more of this type of content in your homepage, consider subscribing. Chao! ^~^
|
||||
|
||||
# Zoom out to outro...
|
||||
Anyways! Here are some enum utilities from the standard library...
|
||||
If you want more of these kind of videos, consider subscribing.
|
||||
chao ^~^!
|
BIN
youtube/video_series/bit_blast/cxx_enums/using_enum.png
Normal file
After Width: | Height: | Size: 84 KiB |