Date: Mon, 30 Jan 2023 13:07:05 +0100
Hello,
Il 30/01/23 13:04, Marcin Jaczewski via Std-Proposals ha scritto:
> T z = {};
> std::array<char, sizeof(z)> a = {};
> return std::bit_cast<decltype(a)>(z) == a;
> }
> ```
>
> It looks like it works for GCC and Clang,
> it needs some guards to allow only simple types (no e.g. `std::string`),
> but the core of this functionality is already available.
It's already in the paper:
https://isocpp.org/files/papers/D2782R0.html#usercode
TL;DR: doesn't work in the general case. You can't bit_cast pointers
during constant evaluation, and it's too strict on the requirements on `T`.
Thanks,
Il 30/01/23 13:04, Marcin Jaczewski via Std-Proposals ha scritto:
> T z = {};
> std::array<char, sizeof(z)> a = {};
> return std::bit_cast<decltype(a)>(z) == a;
> }
> ```
>
> It looks like it works for GCC and Clang,
> it needs some guards to allow only simple types (no e.g. `std::string`),
> but the core of this functionality is already available.
It's already in the paper:
https://isocpp.org/files/papers/D2782R0.html#usercode
TL;DR: doesn't work in the general case. You can't bit_cast pointers
during constant evaluation, and it's too strict on the requirements on `T`.
Thanks,
-- Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer KDAB (France) S.A.S., a KDAB Group company Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com KDAB - The Qt, C++ and OpenGL Experts
Received on 2023-01-30 12:07:08