{"id":98796,"date":"2020-04-05T01:10:37","date_gmt":"2020-04-04T17:10:37","guid":{"rendered":"http:\/\/4563.org\/?p=98796"},"modified":"2020-04-05T01:10:37","modified_gmt":"2020-04-04T17:10:37","slug":"c-%e5%86%85%e7%bd%ae%e7%b1%bb%e5%9e%8b%e5%92%8c%e7%b1%bb%e5%a6%82%e4%bd%95%e4%b8%80%e8%b5%b7%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=98796","title":{"rendered":"c++ \u5185\u7f6e\u7c7b\u578b\u548c\u7c7b\u5982\u4f55\u4e00\u8d77\u5904\u7406"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  c++ \u5185\u7f6e\u7c7b\u578b\u548c\u7c7b\u5982\u4f55\u4e00\u8d77\u5904\u7406               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 23571113 <\/span>  <span><i><\/i> 55<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728\u5199\u5e8f\u5217\u5316\u90e8\u5206\u7684\u65f6\u5019\u9047\u5230\u4e00\u70b9\u95ee\u9898\uff0c\u6211\u60f3\u5bf9\u4e0d\u540c\u7c7b\u578b\u5171\u7528\u540c\u4e00\u5957\u5e8f\u5217\u5316\u7684\u903b\u8f91\u3002 \u5bf9\u4e8e\u7c7b\uff0c\u6211\u7684\u505a\u6cd5\u662f\u5b9a\u4e49\u63a5\u53e3\uff0c\u7c7b\u4f3c:<\/p>\n<pre><code>class Interface { public:  cstring serialize(); }; <\/code><\/pre>\n<p>\u7136\u540e\u8c03\u7528\u63a5\u53e3\u6765\u505a\u5e8f\u5217\u5316<\/p>\n<pre><code>template &lt;typename T&gt; cstring do_serialize(const T &amp;t) {  return t.serialize(); }  template &lt;typename T, typename... Args&gt; cstring do_serialize(const T &amp;t, const Args &amp;... object) {  return t.serialize() + do_serialize(object...); } <\/code><\/pre>\n<p>\u4f46\u662f\u5185\u7f6e\u7c7b\u578b\u6ca1\u6cd5\u5b9e\u73b0 serialize()\uff0c\u6211\u8be5\u600e\u4e48\u5904\u7406\u624d\u6bd4\u8f83\u597d\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"729552\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wwqgtxx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6a21\u677f\u53ef\u4ee5\u5bf9\u7c7b\u578b\u7279\u5316                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"729553\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 23571113 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wwqgtxx \u611f\u8c22\uff0c\u6211 nc \u4e86\uff0c\u60f3\u7740\u53bb\u7528 if \u5224\u65ad\u7c7b\u578b\u4e86\uff0c\u4e8e\u662f int\uff0cconst int\uff0cconst int &amp; &#8230;\u90fd\u4e0d\u662f\u4e00\u4e2a\u7c7b\u578b\u628a\u6211\u641e\u8499\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"729554\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u4e0d\u8981\u7528\u8fd9\u4e2a class Interface\uff0c\u5b83\u5f88\u4e0d cpp<br \/>\u4f60\u8981\u7528\u8fd9\u4e2a\uff1a<br \/>template&lt;class T&gt;<br \/>struct serialize_op <br \/>{<br \/> cstring operator() (T const &amp;) const;<br \/>};                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"729555\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wevsty <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u662f C++17 \u4ee5\u4e0a\uff0c\u5728\u6a21\u677f\u91cc\u5224\u65ad\u7c7b\u578b\u4e5f\u5f88\u65b9\u4fbf\u7684\u3002<br \/>&#8220;`<br \/>template&lt;typename T&gt;<br \/>auto do_serialize(T t)<br \/>{<br \/> if constexpr(std::is_integral&lt;T&gt;::value)<br \/> {return std::to_string(t);} <br \/> else<br \/> {return t;}<br \/>}<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>c++ \u5185\u7f6e\u7c7b\u578b\u548c\u7c7b\u5982\u4f55\u4e00\u8d77\u5904\u7406 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/98796"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=98796"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/98796\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=98796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=98796"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=98796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}