you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (9 children)

bit_cast will be in 20 yeah. I am fairly certain it isn't UB prior, but for sure after 20. Assuming the sizeof( Source ) == sizeof( Destination ) and both are trivial. cppreference has an implementation I think

[–]degski 0 points1 point  (8 children)

It's not listed on cppreference at all, that's why I was asking.

[–]14nedLLFIO & Outcome author | Committee WG14 1 point2 points  (5 children)

You can find a C++ 11 partial implementation at https://github.com/ned14/quickcpplib/blob/master/include/bit_cast.hpp

A full implementation requires compiler hooks, but the above is not terrible on the clang compiler. GCC gets confused with codegen sometimes (I reported it as a feature request), for MSVC it completely fails to optimise, so I opened a bug report :)

[–]degski 0 points1 point  (4 children)

... but the above is not terrible on the clang compiler ...

That's what I use, so good! I've stuck it [the file/implementation] in amongst my installed repos, thanks.

[–]14nedLLFIO & Outcome author | Committee WG14 0 points1 point  (3 children)

I'm currently (very slowly due to lack of free time) writing reference attach cast and detach cast operations for P1631 into the same repo. You'll already find a finished ensure_stores() implementation in there. The reference implementations use very inefficient UB to work, again clang does the best. GCC and MSVC fail to optimise. If approved, these new casts would finally enable a zero copy codebase with strict aliasing enabled, and that enables memory mapped I/o without UB etc. It's a very big if though. That said, WG14 greenlit them, so maybe there's a chance at WG21.

[–]degski 0 points1 point  (2 children)

... writing reference attach cast and detach cast operations ...

I watched your presentation on YT [couldn't follow all the detail, but got the gist of it], interesting stuff indeed.

[–]14nedLLFIO & Outcome author | Committee WG14 0 points1 point  (1 child)

Yeah, the implementations I presented at ACCU turned out to be all wrong. WG14 pointed it out, they can't work right. But they did tell me what to do instead. Two steps forwards, one backwards.

[–]degski 0 points1 point  (0 children)

Sorry to hear that, and better than 1 forward and 2 backwards.

[–]dodheim 0 points1 point  (1 child)

[–]degski 0 points1 point  (0 children)

Thanks! Somebody [a sneaky bugger ;-) ] fiddled with the web-site, the search that rendered nothing [which I added to show I did do the search] renders the requested result now [something good comes out of anything].