{"id":208684,"date":"2020-11-20T02:24:07","date_gmt":"2020-11-19T18:24:07","guid":{"rendered":"http:\/\/4563.org\/?p=208684"},"modified":"2020-11-20T02:24:07","modified_gmt":"2020-11-19T18:24:07","slug":"%e4%b8%80%e4%b8%aa-msvc-%e4%b8%8e-gcc-clang-%e4%b8%8d%e4%b8%80%e8%87%b4%e7%9a%84%e4%be%8b%e5%ad%90%ef%bc%8c%e5%93%aa%e8%be%b9%e6%98%af%e5%af%b9%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=208684","title":{"rendered":"\u4e00\u4e2a msvc \u4e0e gcc\/clang \u4e0d\u4e00\u81f4\u7684\u4f8b\u5b50\uff0c\u54ea\u8fb9\u662f\u5bf9\u7684\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4e00\u4e2a msvc \u4e0e gcc\/clang \u4e0d\u4e00\u81f4\u7684\u4f8b\u5b50\uff0c\u54ea\u8fb9\u662f\u5bf9\u7684\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u57fa\u4e8e C++17\uff0cmsvc \u662f\u6700\u65b0\u7248\u672c\u7684\uff08 16.8.2 \uff09\uff0cgcc\/clang \u4e5f\u662f\u6700\u65b0\u7248\u672c\u7684\uff0c\u53ef\u5728\u7ebf\u8fd0\u884c\uff1agodblot<\/p>\n<pre><code>namespace user {     template&lt;typename T&gt; const T unit { 1 };      template&lt;typename Def&gt;     struct data     {         typename Def::value_type val;     };     template&lt;typename Def&gt; const data&lt;Def&gt; unit&lt;data&lt;Def&gt;&gt; { Def::unit_val() };      struct decimal_def     {         using  value_type = int;         static value_type unit_val() noexcept { return 10; }     };     using decimal_data = data&lt;decimal_def&gt;;     inline const auto decimal_data_unit = unit&lt;decimal_data&gt;; }  #include &lt;iostream&gt; int main() {     std::cout &lt;&lt; user::decimal_data_unit.val &lt;&lt; std::endl; }  <\/code><\/pre>\n<p>\u9884\u671f\u8f93\u51fa\uff1a10<\/p>\n<p>msvc \u8f93\u51fa\uff1a0<\/p>\n<p>gcc\/clang \u8f93\u51fa\uff1a10<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4337863\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u987a\u5e26\u63d0\u4e00\u4e0b\uff0c\u8fd9\u6837\u4fee\u6539\u53ef\u4ee5\u4f7f msvc \u7684\u8f93\u51fa\u7b26\u5408\u9884\u671f\uff1a<\/p>\n<p>inline const auto &amp; decimal_data_unit = unit&lt;decimal_data&gt;;<\/p>\n<p>\u4e3b\u8981\u60f3\u8ba8\u8bba\u4e00\u4e0b\uff0c\u4e0a\u9762\u7684\u5199\u6cd5\u662f\u5426\u6709\u95ee\u9898\uff0c\u8fd8\u662f\u7f16\u8bd1\u5668\u7684 bug \uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4337864\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lcdtyph <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             static constexpr value_type unit_val() noexcept { return 10; }                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4337865\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lcdtyph \u786e\u5b9e\u662f work \u7684\uff0c\u800c\u4e14\u6211\u53d1\u73b0\u95ee\u9898\u8fd8\u8ddf data \u7684\u6784\u9020\u51fd\u6570\u6709\u5173\uff1a<\/p>\n<p>\u5982\u679c\u7ed9 data \u4e0a\u4e00\u4e2a\u666e\u901a\u7684\u6784\u9020\u51fd\u6570\uff0c\u7ed3\u679c\u53c8\u4e0d\u884c\u4e86\uff08\u53d8\u6210 0 \uff09\uff0c\u9700\u8981\u518d\u8fdb\u4e00\u6b65\u628a\u6784\u9020\u51fd\u6570\u4fee\u9970\u6210 constexpr \uff08\u8fd9\u4e5f\u8bf4\u660e\u4f8b\u5b50\u4e2d\u539f\u672c\u9ed8\u8ba4\u7684 aggregate \u6784\u9020\u51fd\u6570\u662f constexpr\uff0c\u4f46\u6211\u597d\u50cf\u6ca1\u627e\u5230\u6807\u51c6\u8bf4\u660e\uff1f\uff09<\/p>\n<p>\u6240\u4ee5\u95ee\u9898\u662f\uff0c\u8fd9\u4e2a\u884c\u4e3a\u5230\u5e95\u662f msvc \u6bd4\u8f83\u6b63\u786e\u8fd8\u662f gcc \u6bd4\u8f83\u6b63\u786e\u5462\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4337866\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lcdtyph <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wutiantong <br \/>\u6211\u5bf9\u6807\u51c6\u4e86\u89e3\u7684\u4e0d\u6df1\uff0c\u8bf4\u4e0d\u4e0a\u54ea\u8fb9\u662f\u5bf9\u7684\u2026\u6211\u4e5f\u6ca1\u6709 msvc \u73af\u5883\uff0c\u4e0a\u9762\u7684\u4fee\u6539\u662f\u6839\u636e\u7ecf\u9a8c\u6539\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4337867\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Wirbelwind <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wutiantong \u4e0d\u662f\u6784\u9020\u51fd\u6570\u7684\u95ee\u9898<\/p>\n<p>\u5728\u521d\u59cb\u5316\u7684\u65f6\u5019\u9700\u8981\u8c03\u7528 unit_val()\uff0c\u95ee\u9898\u662f\u7f16\u8bd1\u5668 \u4ec0\u4e48\u65f6\u5019 \u7528 unit_val()\u7684\u8fd4\u56de\u503c\u5bf9\u5b83\u8d4b\u503c                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a msvc \u4e0e gcc\/cla&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\/208684"}],"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=208684"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/208684\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=208684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=208684"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=208684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}