diff options
author | Neil MacIntosh <neilmac@microsoft.com> | 2016-09-20 08:47:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-20 08:47:49 -0700 |
commit | fd5ad87bf25cb5e87104ee58106dee9bc809cd93 (patch) | |
tree | fe2d4ac1a3071957a02331cee5aa386cc91c9866 | |
parent | e4de6cccdd1a8f90ff0268324bdf965a0a891624 (diff) | |
parent | 6cf154e067550440e9580cad0744afd12e1ccafd (diff) | |
download | platform_external_Microsoft-GSL-fd5ad87bf25cb5e87104ee58106dee9bc809cd93.tar.gz platform_external_Microsoft-GSL-fd5ad87bf25cb5e87104ee58106dee9bc809cd93.tar.bz2 platform_external_Microsoft-GSL-fd5ad87bf25cb5e87104ee58106dee9bc809cd93.zip |
Add tests for to_integer(), fix to_integer()
-rw-r--r-- | gsl/gsl_byte | 2 | ||||
-rw-r--r-- | tests/byte_tests.cpp | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/gsl/gsl_byte b/gsl/gsl_byte index ab5e4e3..9962ab4 100644 --- a/gsl/gsl_byte +++ b/gsl/gsl_byte @@ -103,7 +103,7 @@ inline constexpr byte operator~(byte b) noexcept { return byte(~static_cast<unsi template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>> inline constexpr IntegerType to_integer(byte b) noexcept { - return {b}; + return static_cast<IntegerType>(b); } template<bool E, typename T> diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp index 59ff0cd..3bbf382 100644 --- a/tests/byte_tests.cpp +++ b/tests/byte_tests.cpp @@ -96,6 +96,24 @@ SUITE(byte_tests) a >>= 4; CHECK(a == to_byte<0x0F>()); } + + TEST(to_integer) + { + byte b = to_byte<0x12>(); + + CHECK(0x12 == gsl::to_integer<char>(b)); + CHECK(0x12 == gsl::to_integer<short>(b)); + CHECK(0x12 == gsl::to_integer<long>(b)); + CHECK(0x12 == gsl::to_integer<long long>(b)); + + CHECK(0x12 == gsl::to_integer<unsigned char>(b)); + CHECK(0x12 == gsl::to_integer<unsigned short>(b)); + CHECK(0x12 == gsl::to_integer<unsigned long>(b)); + CHECK(0x12 == gsl::to_integer<unsigned long long>(b)); + +// CHECK(0x12 == gsl::to_integer<float>(b)); // expect compile-time error +// CHECK(0x12 == gsl::to_integer<double>(b)); // expect compile-time error + } } } |