{"id":48,"date":"2015-04-23T00:33:17","date_gmt":"2015-04-22T15:33:17","guid":{"rendered":"http:\/\/milennium9.godohosting.com\/wordpress\/?p=48"},"modified":"2015-08-04T16:01:52","modified_gmt":"2015-08-04T07:01:52","slug":"template-%ec%9c%bc%eb%a1%9c-container-%ec%a0%84%eb%8b%ac%eb%b0%9b%ea%b3%a0-enable_if%eb%a1%9c-%ec%a1%b0%ea%b1%b4%ec%97%90-%eb%94%b0%eb%9d%bc-%ed%8a%b9%ec%88%98%ed%99%94%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"http:\/\/milennium9.godohosting.com\/wordpress\/?p=48","title":{"rendered":"template \uc73c\ub85c container \uc804\ub2ec\ubc1b\uace0 enable_if\ub85c \uc870\uac74\uc5d0 \ub530\ub77c \ud2b9\uc218\ud654\ud558\uae30"},"content":{"rendered":"<p>\uc624\ub298 \ucf54\ub4dc\ub97c \uc791\uc131\ud558\ub358 \uc911 Serializer \uad00\ub828 \ucf54\ub4dc\uc5d0\uc11c vector, set, map \ub4f1\uc758 \ucee8\ud14c\uc774\ub108\ub97c \uc704\ud55c read, write template \ud568\uc218\ub4e4\uc774 \uc120\uc5b8\ub418\uc5b4 \uc788\ub294 \uac83\uc744 \ubcf4\uac8c \ub418\uc5c8\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ud558\uc9c0\ub9cc \ub0b4\ubd80\uc801\uc778 \uad6c\uc870\ub294 value\ub9cc \ub2e4\ub8e8\ub294 vector, deque, list, set \uacfc \uac19\uc740 \ucee8\ud14c\uc774\ub108\uc640 key, value\ub97c \ud568\uaed8 \ub2e4\ub8e8\ub294 map, multimap, hash_map, unordered_map \uac19\uc740 \ucee8\ud14c\uc774\ub108 \ub450 \ubd84\ub958\ub85c \ub098\ub220\uc838\uc788\uace0 \uc911\ubcf5\ub41c \ucf54\ub4dc\uac00 \ubcf4\uc600\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\uac8c\ub2e4\uac00 stdext::hash_map \ub9cc \ud2b9\uc218\ud654 \ub418\uc5b4 \uc788\uc5b4\uc11c std::hash_map \ub4f1 \ud2b9\uc218\ud654 \ub418\uc9c0 \uc54a\uc740 \ucee8\ud14c\uc774\ub108\ub97c \uc0ac\uc6a9\ud558\ub824\uba74 \ub610 \ucf54\ub4dc\ub97c \ubcf5\uc0ac\ud574\uc11c \ud2b9\uc218\ud654 \ud558\ub294 \uac83\uc744 \ubc18\ubcf5\ud574\uc57c \ud588\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\uc774\uac70 \uc660\uc9c0 template&lt; template&lt;class,class&gt; class T&gt; \ud45c\ud604\uc73c\ub85c \uad73\uc774 \ud2b9\uc218\ud654\ub97c \ub9e4\ubc88 \ucd94\uac00\ud558\uc9c0 \uc54a\uace0\ub3c4 \ub2e4\uc591\ud55c \ucee8\ud14c\uc774\ub108\uc758 Serialize\ub97c \ud560 \uc218 \uc788\uaca0\ub2e4 \uc2f6\uc5b4\uc11c \uad00\ub828 \ucf54\ub4dc\ub97c \ub300\ub7b5 \uc544\ub798 \ucf54\ub4dc\uc640 \ub3d9\uc77c\ud55c \uc811\uadfc \ubc95\uc73c\ub85c \uc218\uc815\uc744 \ud588\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"lang:c++ decode:true \" title=\"template template\">#include &lt;iostream&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;deque&gt;\r\n\r\nusing namespace std;\r\n\r\n\/\/ template \uc778\uc790 \ub450\uac1c\ub97c \ubc1b\ub294 Container T\ub97c \ubc1b\ub294 \ud568\uc218\uc785\ub2c8\ub2e4.\r\ntemplate&lt; template&lt;class,class&gt; class T, class V, class A&gt;\r\nvoid push_back( T&lt;V,A&gt;&amp; con, V&amp;&amp; v) {\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n}\r\n\r\n\/\/ vector, deque \ubaa8\ub450 push_back \ud568\uc218\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\r\nint main() {\r\n\tvector&lt;int&gt; v;\r\n\tdeque&lt;int&gt; d;\r\n\r\n\tpush_back(v, 1);\r\n\tpush_back(d, 1);\r\n\treturn 0;\r\n}<\/pre>\n<p>\uc5ec\uae30\uc11c \uc0c8\ub86d\uac8c \ub9cc\ub09c \ubb38\uc81c\ub294 Deserialize\uc758 \uacbd\uc6b0 vector\ub294 size\ub97c \ubbf8\ub9ac \uc54c\uace0 \uc788\uae30 \ub54c\ubb38\uc5d0 reserve \ud568\uc218\ub97c \ud638\ucd9c\ud574 \uc8fc\uace0 \uc788\uc5c8\uc2b5\ub2c8\ub2e4. \uadf8\ub7ec\uba74 reserve \ud568\uc218\ub97c \uac00\uc9c4 \ucee8\ud14c\uc774\ub108\uc640 \uc544\ub2cc \ucee8\ud14c\uc774\ub108\ub97c \uad6c\ubd84\ud558\uc5ec \ud2b9\uc218\ud654\ub97c \ud574\uc918\uc57c \ud558\ub294\ub370 \uc544\ub798\uc758 \ucf54\ub4dc\uc640 \uac19\uc774 enable_if\ub97c \uc0ac\uc6a9\ud558\uace0 member \ud568\uc218\uc758 \uc874\uc7ac\ub97c \ud655\uc778\ud574 \uc8fc\ub294 template class\ub97c \uad6c\ud604\ud574 \uc8fc\uba74 \uac00\ub2a5\ud569\ub2c8\ub2e4.<\/p>\n<pre class=\"lang:default decode:true \" title=\"enable_if\">#include &lt;iostream&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;deque&gt;\r\n#include &lt;type_traits&gt;\r\n\r\nusing namespace std;\r\n\r\n\/\/ \uac1d\uccb4\uac00 \uba64\ubc84\ud568\uc218 reserve\ub97c \uac00\uc9c0\uace0 \uc788\ub294\uc9c0 \ud655\uc778\ud569\ub2c8\ub2e4.\r\ntemplate&lt;class T&gt;\r\nclass has_member_reserve {\r\n\tusing no  = char[1];\r\n\tusing yes = char[2];\r\n\t\r\n\/\/ SFINAE \uaddc\uce59\uc5d0 \uc758\ud574\uc11c reserve \ud568\uc218\uac00 \uc5c6\uc73c\uba74 no\ub97c \ubc18\ud658\ud569\ub2c8\ub2e4.\r\n\ttemplate&lt;class C&gt;\r\n\tstatic yes&amp;  test( decltype(&amp;C::reserve));\r\n\ttemplate&lt;class C&gt;\r\n\tstatic no&amp;   test( ... );\r\npublic:\r\n\tstatic const bool value = sizeof(test&lt;T&gt;(nullptr)) == sizeof(yes);\r\n};\r\n\r\n\/\/ enable_if\ub85c reserve \ud568\uc218\uc758 \uc874\uc7ac\uc5d0 \ub530\ub77c \uc801\uc808\ud55c push_back \ud568\uc218\ub97c \ud638\ucd9c\ud569\ub2c8\ub2e4.\r\n\/\/ \uc5ec\uae30\uc5d0\uc11c\ub3c4 SFINAE \uc6d0\uce59\uc774 \uc801\uc6a9\ub429\ub2c8\ub2e4.\r\ntemplate&lt; template&lt;class,class&gt; class T, class V, class A&gt;\r\nvoid push_back( T&lt;V,A&gt;&amp; con, V&amp;&amp; v, typename enable_if&lt;has_member_reserve&lt;T&lt;V,A&gt;&gt;::value&gt;::type* = nullptr) {\r\n\tcon.reserve(5);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcout &lt;&lt; \"this container has reserve member function\" &lt;&lt; endl;\r\n}\r\n\r\ntemplate&lt; template&lt;class,class&gt; class T, class V, class A&gt;\r\nvoid push_back( T&lt;V,A&gt;&amp; con, V&amp;&amp; v, typename enable_if&lt;has_member_reserve&lt;T&lt;V,A&gt;&gt;::value==false&gt;::type* = nullptr) {\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcon.push_back(v);\r\n\tcout &lt;&lt; \"this container does not have reserve member function\" &lt;&lt; endl;\r\n}\r\n\r\nint main() {\r\n\tvector&lt;int&gt; v;\r\n\tdeque&lt;int&gt; d;\r\n\t\r\n\tpush_back(v, 1);\r\n\tpush_back(d, 1);\r\n\treturn 0;\r\n}<\/pre>\n<p>\uc774\uc81c \uc0ac\uc6a9\uc790\ub294 Container\uc5d0 \ub300\ud55c \ud2b9\ubcc4\ud55c \uc81c\ud55c\uc744 \ub290\ub084 \uc218 \uc5c6\uace0 \ub610 \uc54c\uc544\uc11c reserve\uae4c\uc9c0 \ud638\ucd9c\ud574 \uc8fc\ub294 \uc88b\uc740 \ucf54\ub4dc\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\uac8c \ub418\uc5c8\uc2b5\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc624\ub298 \ucf54\ub4dc\ub97c \uc791\uc131\ud558\ub358 \uc911 Serializer \uad00\ub828 \ucf54\ub4dc\uc5d0\uc11c vector, set, map \ub4f1\uc758 \ucee8\ud14c\uc774\ub108\ub97c \uc704\ud55c read, write template \ud568\uc218\ub4e4\uc774 \uc120\uc5b8\ub418\uc5b4 \uc788\ub294 \uac83\uc744 \ubcf4\uac8c \ub418\uc5c8\uc2b5\ub2c8\ub2e4. \ud558\uc9c0\ub9cc \ub0b4\ubd80\uc801\uc778 \uad6c\uc870\ub294 value\ub9cc \ub2e4\ub8e8\ub294 vector, deque, list, set \uacfc \uac19\uc740 \ucee8\ud14c\uc774\ub108\uc640 key, value\ub97c \ud568\uaed8 \ub2e4\ub8e8\ub294 map, multimap, hash_map, unordered_map \uac19\uc740 \ucee8\ud14c\uc774\ub108 \ub450 \ubd84\ub958\ub85c \ub098\ub220\uc838\uc788\uace0 \uc911\ubcf5\ub41c \ucf54\ub4dc\uac00 \ubcf4\uc600\uc2b5\ub2c8\ub2e4. \uac8c\ub2e4\uac00 stdext::hash_map \ub9cc \ud2b9\uc218\ud654 \ub418\uc5b4 &hellip; <a href=\"http:\/\/milennium9.godohosting.com\/wordpress\/?p=48\" class=\"more-link\"><span class=\"screen-reader-text\">template \uc73c\ub85c container \uc804\ub2ec\ubc1b\uace0 enable_if\ub85c \uc870\uac74\uc5d0 \ub530\ub77c \ud2b9\uc218\ud654\ud558\uae30<\/span> \ub354\ubcf4\uae30 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0},"categories":[4],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5PypW-M","_links":{"self":[{"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/48"}],"collection":[{"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=48"}],"version-history":[{"count":3,"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":56,"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions\/56"}],"wp:attachment":[{"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/milennium9.godohosting.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}