Created
December 26, 2017 12:01
-
-
Save belltailjp/ec3249ba935fff7c825a5fc7faae5ab7 to your computer and use it in GitHub Desktop.
Just a confirm of whether all the information of optional is preserved or not after memory bytes copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <experimental/optional> | |
int main() | |
{ | |
std::experimental::optional<int> t; | |
//t = 100; // comment in/out | |
unsigned char *p = new unsigned char[sizeof(t)]; | |
// copy memory | |
std::copy((char*)&t, (char*)&t + sizeof(t), p); | |
std::experimental::optional<int> t2 = *(std::experimental::optional<int>*)p; | |
if(t2) | |
std::cout << *t2 << std::endl; | |
} | |
//g++ optional.cpp -std=c++14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment