Skip to content

Instantly share code, notes, and snippets.

@usagi
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save usagi/10733058 to your computer and use it in GitHub Desktop.

Select an option

Save usagi/10733058 to your computer and use it in GitHub Desktop.
#include <cassert>
#include <boost/property_tree/ptree.hpp>
int main()
{
using namespace boost::property_tree;
ptree pt;
int x = 123;
class Y { } y;
pt.put("x.ptr", &x);
pt.put("y.ptr", &y);
auto px = static_cast<decltype(x)*>(pt.get<void*>("x.ptr"));
auto py = static_cast<decltype(y)*>(pt.get<void*>("y.ptr"));
std::cout
<< px << " " << typeid(px).name() << "\n"
<< &x << " " << typeid(&x).name() << "\n"
<< py << " " << typeid(py).name() << "\n"
<< &y << " " << typeid(&y).name() << "\n"
;
assert(px == &x);
assert(py == &y);
}
0x7fffd9d47604 Pi
0x7fffd9d47604 Pi
0x7fffd9d47600 PZ4mainE1Y
0x7fffd9d47600 PZ4mainE1Y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment