I'd like to have a type, which is like unsigned char
:
- sizeof is 1
- integer values can be assigned to it (without any casts)
- bit manipulations are allowed
- arithmetic is allowed, but not a must
- unsigned
- trivially copyable
But, unlike unsigned char
, it is not allowed to alias. I mean, a type, which doesn't have the exception [basic.lval/11.8]:
If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined:
[...]
- a char, unsigned char, or std::byte type.
Is it possible to have a type like this?
The reason: I almost never use unsigned char
's aliasing property. So, I'd like to use a type instead, which doesn't prevent certain kind of optimizations (note, I asked this question because I actually have functions, which aren't optimized well, because of the aliasing-allowing property of unsigned char
). So, I'd like to have a type for which this is true: "don't pay for what you don't use".
Here's an example, where unsigned char
prevents optimization: Using this pointer causes strange deoptimization in hot loop