Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <cassert>
  2. #include <cstring>
  3. #include <new>
  4.  
  5. int main()
  6. {
  7.     alignas(int) unsigned char buff1[sizeof(int)];
  8.     alignas(int) unsigned char buff2[sizeof(int)];
  9.    
  10.     new (buff1) int {42};
  11.     std::memcpy(buff2, buff1, sizeof(buff1));
  12.    
  13.     assert(*std::launder(reinterpret_cast<int*>(buff2)) == 42); // is it ok?
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement