forked from microsoft/GSL
Issue: #329
This is my best attempt at fixing the issues raised by @gdr-at-ms while supporting VS2013, VS2015, providing shorter syntax than the static_cast and giving developer meaningful errors when they do the wrong thing.
This commit is contained in:
+24
-19
@@ -45,7 +45,12 @@ SUITE(byte_tests)
|
||||
}
|
||||
|
||||
{
|
||||
byte b = to_byte(12);
|
||||
byte b = to_byte<12>();
|
||||
CHECK(static_cast<unsigned char>(b) == 12);
|
||||
}
|
||||
{
|
||||
unsigned char uc = 12;
|
||||
byte b = to_byte(uc);
|
||||
CHECK(static_cast<unsigned char>(b) == 12);
|
||||
}
|
||||
|
||||
@@ -58,38 +63,38 @@ SUITE(byte_tests)
|
||||
|
||||
TEST(bitwise_operations)
|
||||
{
|
||||
byte b = to_byte(0xFF);
|
||||
byte b = to_byte<0xFF>();
|
||||
|
||||
byte a = to_byte(0x00);
|
||||
CHECK((b | a) == to_byte(0xFF));
|
||||
CHECK(a == to_byte(0x00));
|
||||
byte a = to_byte<0x00>();
|
||||
CHECK((b | a) == to_byte<0xFF>());
|
||||
CHECK(a == to_byte<0x00>());
|
||||
|
||||
a |= b;
|
||||
CHECK(a == to_byte(0xFF));
|
||||
CHECK(a == to_byte<0xFF>());
|
||||
|
||||
a = to_byte(0x01);
|
||||
CHECK((b & a) == to_byte(0x01));
|
||||
a = to_byte<0x01>();
|
||||
CHECK((b & a) == to_byte<0x01>());
|
||||
|
||||
a &= b;
|
||||
CHECK(a == to_byte(0x01));
|
||||
CHECK(a == to_byte<0x01>());
|
||||
|
||||
CHECK((b ^ a) == to_byte(0xFE));
|
||||
CHECK((b ^ a) == to_byte<0xFE>());
|
||||
|
||||
CHECK(a == to_byte(0x01));
|
||||
CHECK(a == to_byte<0x01>());
|
||||
a ^= b;
|
||||
CHECK(a == to_byte(0xFE));
|
||||
CHECK(a == to_byte<0xFE>());
|
||||
|
||||
a = to_byte(0x01);
|
||||
CHECK(~a == to_byte(0xFE));
|
||||
a = to_byte<0x01>();
|
||||
CHECK(~a == to_byte<0xFE>());
|
||||
|
||||
a = to_byte(0xFF);
|
||||
CHECK((a << 4) == to_byte(0xF0));
|
||||
CHECK((a >> 4) == to_byte(0x0F));
|
||||
a = to_byte<0xFF>();
|
||||
CHECK((a << 4) == to_byte<0xF0>());
|
||||
CHECK((a >> 4) == to_byte<0x0F>());
|
||||
|
||||
a <<= 4;
|
||||
CHECK(a == to_byte(0xF0));
|
||||
CHECK(a == to_byte<0xF0>());
|
||||
a >>= 4;
|
||||
CHECK(a == to_byte(0x0F));
|
||||
CHECK(a == to_byte<0x0F>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user