bit-cast Questions

1

Solved

Is it allowed to apply std::bit_cast to an object of empty class, converting it to some not-empty class of the same size? And especially is it allowed to do in a constant expression? I was surprise...
Wnw asked 31/3, 2024 at 20:10

1

I want to know how to use std::bit_cast in a well-defined way, noticeably in presence of indetermined bits. When is std::bit_cast usage defined behavior, when is it undefined behavior? Thus I need ...
Brant asked 13/2, 2024 at 14:30

1

While experimenting with compile-time string manipulation, I've encountered a strange phenomenon: #include <bit> constexpr char str[4] = "abc"; // error: constexpr variable 'x' mu...
Forseti asked 9/5, 2021 at 0:32

2

Solved

I'm trying to get a bitmask from a bitfield struct, at compile time. One of the tricks that I tried, which looks promising to me, is using std::bit_cast, because it is supposed to be constexpr. My ...
Commemoration asked 18/8, 2023 at 19:53

1

Solved

A colleague showed me a C++20 program where a closure object is virtually created using std::bit_cast from the value that it captures: #include <bit> #include <iostream> class A { int...
Pamper asked 18/8, 2021 at 8:19

2

Solved

C++20 introduced std::bit_cast for treating the same bits as if they were a different type. So, basically it does this: template <typename T1, typename T2> T2 undefined_bit_cast(T1 v1) { T1 ...
Wernerwernerite asked 13/5, 2021 at 14:48

2

Solved

std::bit_cast is apparently being introduced in c++20. and std::start_lifetime_as is proposed for c++23 (from P0593R5). As they appear to both require that the datatypes involved be trivial anyways...
Reiterate asked 6/10, 2019 at 3:38

3

Solved

In his recent talk “Type punning in modern C++” Timur Doumler said that std::bit_cast cannot be used to bit cast a float into an unsigned char[4] because C-style arrays cannot be returned from a fu...
Resonator asked 10/10, 2019 at 9:59

2

Solved

std::bit-cast was introduced in the C++20 standard. I know that reinterpret_cast is not suitable for this job due to type aliasing rules. However, why did they choose not to extend reinterpret_cast...
Sewellel asked 20/11, 2018 at 21:16
1

© 2022 - 2025 — McMap. All rights reserved.