{"id":131,"date":"2018-12-30T01:17:11","date_gmt":"2018-12-30T04:17:11","guid":{"rendered":"http:\/\/35.243.195.209\/?p=131"},"modified":"2019-01-01T11:27:57","modified_gmt":"2019-01-01T19:27:57","slug":"syntax-sugar-in-c","status":"publish","type":"post","link":"https:\/\/nanzhou.cc\/index.php\/2018\/12\/30\/syntax-sugar-in-c\/","title":{"rendered":"Syntax Sugar in C++"},"content":{"rendered":"<h2>Summary<\/h2>\n<p>In this post, I will introduce some syntax sugar in C++.<\/p>\n<h2>Content<\/h2>\n<p><a href=\"#1\">1. Initializer List Constructor<\/a><br \/>\n<a href=\"#2\">2. Range in Container Construtor<\/a><br \/>\n<a href=\"#3\">3. Copy Constructor<\/a><\/p>\n<h2>Details<\/h2>\n<p><a name='1'><\/a><\/p>\n<h3>1. Initializer List Constructor<\/h3>\n<pre><code class=\"c\">vector&lt;int&gt; vec({1,2,3,4,5});\nunordered_map&lt;char, int&gt; char_counter ({{'a', 1}, {'b', 2}, {'c', 3}});\n<\/code><\/pre>\n<p>The syntax below is also legal.<\/p>\n<pre><code class=\"c\">\/\/ use {} in vector\nvector&lt;int&gt; nums = {1,2,3,4};\nvector&lt;int&gt; nums {1,2,3,4};\n<\/code><\/pre>\n<p><a name='2'><\/a><\/p>\n<h3>2. Range in Container Construtor<\/h3>\n<pre><code class=\"c\">\/\/ use iterator\nvector&lt;int&gt; nums = {1,2,3,4};\nunordered_set&lt;int&gt; nums_set(nums.begin(), nums.end());\n<\/code><\/pre>\n<p><a name='3'><\/a><\/p>\n<h3>3. Copy Constructor<\/h3>\n<pre><code class=\"c\">vector&lt;int&gt; copy(nums.begin(), nums.end());\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Summary In this post, I will introduce some syntax sugar in C++. Content 1. Initializer List Constructor 2. Range in Container Construtor 3. Copy Constructor Details 1. Initializer List Constructor vector&lt;int&gt; vec({1,2,3,4,5}); unordered_map&lt;char, int&gt; char_counter ({{&#8216;a&#8217;, 1}, {&#8216;b&#8217;, 2}, {&#8216;c&#8217;, 3}}); The syntax below is also legal. \/\/ use {} in vector vector&lt;int&gt; nums =&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[],"class_list":["post-131","post","type-post","status-publish","format-standard","hentry","category-c","category-proglang"],"_links":{"self":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/comments?post=131"}],"version-history":[{"count":5,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/131\/revisions\/145"}],"wp:attachment":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/media?parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/categories?post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/tags?post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}