{"published":"2020-03-31 00:00:00","author_url":"https://blog.hatena.ne.jp/yohhoy/","width":"100%","provider_url":"https://hatena.blog","blog_title":"yohhoy\u306e\u65e5\u8a18","description":"\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9eC++\u306b\u304a\u3044\u3066\u3001\u5358\u4e00\u30e1\u30f3\u30d0\u3057\u304b\u542b\u307e\u306a\u3044\u5171\u7528\u4f53(union)\u3092\u7528\u3044\u308b\u3068\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u660e\u793a\u7684\u306a\u751f\u6210\uff0f\u7834\u68c4\u64cd\u4f5c\u304c\u53ef\u80fd\u3068\u306a\u308b\u3002\u8ca7\u8005(poor man's)\u306eOptional\u3002 #include <iostream> template <typename T> union Wrapper { // \u5171\u7528\u4f53\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf/\u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u5b9a\u7fa9\u306f\u5fc5\u9808 Wrapper() {} ~Wrapper() {} // \u660e\u793a\u7684\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u521d\u671f\u5316 void init() { new (&obj_) Holder; } // \u660e\u793a\u7684\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5ec3\u68c4 void destroy() { obj_.~Hol\u2026","version":"1.0","height":"190","title":"\u5358\u4e00\u30e1\u30f3\u30d0union\u306e\u4f7f\u3044\u9053","blog_url":"https://yohhoy.hatenadiary.jp/","type":"rich","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fyohhoy.hatenadiary.jp%2Fentry%2F20200331%2Fp1\" title=\"\u5358\u4e00\u30e1\u30f3\u30d0union\u306e\u4f7f\u3044\u9053 - yohhoy\u306e\u65e5\u8a18\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","author_name":"yohhoy","url":"https://yohhoy.hatenadiary.jp/entry/20200331/p1","categories":["C++"],"provider_name":"Hatena Blog","image_url":null}