microsoft / GSL

Guidelines Support Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: How to print a gsl::byte?

honey-speaks-tech opened this issue · comments

Hi all,
We are using C++14 and we are happily using Microsoft GSL library (ms-gsl 4.0.0). We are trying an example to print some gsl::byte values.
Here is the godbolt link: https://godbolt.org/z/5cKbvWsK3

For some reason, we are yet not able to figure out how gsl::byte could be used and printed in our codebase.
Could you please help us sort out this issue? In the example, we would like to print both individual gsl::byte and also gsl::byte values in the array. We need to use this gsl::byte variables in our unit tests as well with google test macros such as EXPECT_* or ASSERT_*.

We would definitely appreciate any leads on this.

Thank you,
Honey

Honey Sukesan

Hi @honey-speaks-tech,

I tweaked your example to something that works for me: https://godbolt.org/z/8c11Gv495.
The main difference in implementation is that in v1, the byte is converted into an int type as opposed to std::uint8_t, since doing the latter will attempt to interpret the byte value as an ASCII character, as opposed to a numerical value. See this discussion.

If this doesn't answer your question, could you please provide an expected output alongside the output you are seeing?

Hi @dmitrykobets-msft,
Sorry for the delay in response. This perfectly answers my question. Thank you for the support.

Best,
Honey

Honey Sukesan