How it works...
The implementation in the previous section enables us to define binary literals of the form 1010_b8 (a byte8 value of decimal 10) or 000010101100_b16 (a byte16 value of decimal 2130496). However, we want to make sure that we do not exceed the number of digits for each type. In other words, values such as 111100001_b8 should be illegal and the compiler should yield an error.
First of all, we define everything inside a namespace called binary and start with introducing several type aliases (byte8, byte16, and byte32).
The literal operator templates are defined in a nested namespace called binary_literal_internals. This is a good practice in order to avoid name collision with other literal operators from other namespaces. Should ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access