0

I'm attempting to use std::byte for the first time but I'm failing to initialize the value.

#include <cstddef>

double red_double = 0.5;
auto red_byte = std::byte(red_double * 255);

Results in: error C2440: '<function-style-cast>': cannot convert from 'double' to 'std::byte'

This seems like a mind-numbingly simple task but I guess std::byte works differently to normal types. Any help would be appreciated!

I'm compiling with MSVC 19.22 which apparently claims to fully support std::byte: https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=vs-2019

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
Flux
  • 1
  • 2

1 Answers1

0

I was able to compile the code with clang 8.0 and gcc 9.2, but the code failed to compile with msvc 19.22 compiler. Hence there is no full support for std::byte with msvc compiler as of now.

By the way there is nothing wrong with your code.

ritesh sangani
  • 280
  • 3
  • 8
  • Thanks for the help. Interestingly, MSVC claim it is supported https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=vs-2019 – Flux Sep 18 '19 at 23:45