<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8445934432797432506</id><updated>2024-08-28T16:48:19.776-07:00</updated><title type='text'>street programmer</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-2480717431229936953</id><published>2020-06-12T21:49:00.003-07:00</published><updated>2020-06-19T20:45:30.742-07:00</updated><title type='text'>Assignment problem</title><content type='html'>&lt;a href=&quot;https://www.geeksforgeeks.org/hungarian-algorithm-assignment-problem-set-1-introduction/&quot;&gt;https://www.geeksforgeeks.org/hungarian-algorithm-assignment-problem-set-1-introduction/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
tornado tutorials:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://emptysqua.re/blog/refactoring-tornado-coroutines/&quot;&gt;refactoring-tornado-coroutines&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/2480717431229936953/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/06/assignment-problem.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2480717431229936953'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2480717431229936953'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/06/assignment-problem.html' title='Assignment problem'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-933422100223141818</id><published>2020-05-17T14:29:00.000-07:00</published><updated>2020-05-17T14:29:18.030-07:00</updated><title type='text'></title><content type='html'>Systemd:&lt;br /&gt;
&lt;br /&gt;
1. overview and cheatsheet&lt;br /&gt;
&lt;a href=&quot;https://www.linux.com/training-tutorials/understanding-and-using-systemd/&quot;&gt;Overview and cheatsheet&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/933422100223141818/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/05/systemd-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/933422100223141818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/933422100223141818'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/05/systemd-1.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-5924183690497080296</id><published>2020-04-26T19:09:00.001-07:00</published><updated>2020-04-26T19:09:03.731-07:00</updated><title type='text'>mock</title><content type='html'>&lt;a href=&quot;https://chromium.googlesource.com/external/github.com/google/googletest/+/release-1.8.0/googlemock/docs/ForDummies.md&quot;&gt;mock&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/5924183690497080296/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/mock.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/5924183690497080296'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/5924183690497080296'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/mock.html' title='mock'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-7543136706403798059</id><published>2020-04-03T19:40:00.000-07:00</published><updated>2020-04-03T19:40:17.353-07:00</updated><title type='text'>Linux source code</title><content type='html'>&lt;a href=&quot;https://elixir.bootlin.com/linux/v5.6-rc7/source/include/linux/skbuff.h#L711&quot;&gt;elixir.bootlin.com&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/7543136706403798059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/linux-source-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7543136706403798059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7543136706403798059'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/linux-source-code.html' title='Linux source code'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-8129362546455589013</id><published>2020-04-02T21:08:00.002-07:00</published><updated>2020-04-03T08:13:55.905-07:00</updated><title type='text'>120 sseconds</title><content type='html'>&lt;a href=&quot;https://www.blackmoreops.com/2014/09/22/linux-kernel-panic-issue-fix-hung_task_timeout_secs-blocked-120-seconds-problem/&quot;&gt;120 seconds&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
120 seconds&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://pingcap.com/blog/try-to-fix-two-linux-kernel-bugs-while-testing-tidb-operator-in-k8s/&quot;&gt;SLUB allocation failure&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/8129362546455589013/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/120-sseconds.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/8129362546455589013'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/8129362546455589013'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/120-sseconds.html' title='120 sseconds'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-7063190169414597096</id><published>2020-04-02T05:31:00.000-07:00</published><updated>2020-04-02T05:31:12.566-07:00</updated><title type='text'>Write a linux kernel module</title><content type='html'>&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://blog.sourcerer.io/writing-a-simple-linux-kernel-module-d9dc3762c234&quot;&gt;How to write a simple linux kernel module&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/7063190169414597096/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/write-linux-kernel-module.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7063190169414597096'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7063190169414597096'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/write-linux-kernel-module.html' title='Write a linux kernel module'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-345311107886373582</id><published>2020-04-01T12:56:00.002-07:00</published><updated>2020-04-03T09:09:38.788-07:00</updated><title type='text'>linux perf tool</title><content type='html'>&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;http://balodeamit.blogspot.com/2014/06/perf-linux-profiling-tool.html&quot;&gt;perf tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/brendangregg/perf-tools&quot;&gt;perf-tools&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/345311107886373582/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/linux-perf-tool.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/345311107886373582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/345311107886373582'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/04/linux-perf-tool.html' title='linux perf tool'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-7256969095984948104</id><published>2020-03-30T20:34:00.001-07:00</published><updated>2020-04-01T13:52:39.372-07:00</updated><title type='text'>linux kernel books</title><content type='html'>1.&amp;nbsp;&lt;a href=&quot;https://www.kernel.org/doc/gorman/html/understand/understand001.html&quot;&gt;linux memory management&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
2.&amp;nbsp;&lt;a href=&quot;https://engineering.linkedin.com/performance/optimizing-linux-memory-management-low-latency-high-throughput-databases&quot;&gt;linked in direct men reclaim mode&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Kernel runs out packet buffers:&lt;br /&gt;
1.&amp;nbsp;&lt;a href=&quot;https://support.solarflare.com/index.php/component/cognidox/?file=SF-114811-KI-2_Blocking_behaviour_when_Onload_runs_out_of_packet_buffers.htm&amp;amp;catid=0&amp;amp;view=embed&amp;amp;id=3013&quot;&gt;unload runs out of packet buffers&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
2.&amp;nbsp;&lt;a href=&quot;http://vger.kernel.org/~davem/&quot;&gt;How SKB (Socket Buffer) works.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
3.&amp;nbsp;&lt;a href=&quot;https://ref.onixs.biz/lost-multicast-packets-troubleshooting.html&quot;&gt;How to resolve packet loss&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
4.&amp;nbsp;&lt;a href=&quot;https://web.archive.org/web/20080419012851/http://people.redhat.com/dduval/kernel/min_free_kbytes.html&quot;&gt;Linux Zone LOW/HIGH/MIN&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
5.&amp;nbsp;&lt;a href=&quot;http://balodeamit.blogspot.com/2015/11/deep-dive-into-linux-memory-management.html&quot;&gt;Deep into linux memory management&lt;/a&gt;&lt;br /&gt;
6.&lt;a href=&quot;https://github.com/majek/openonload&quot;&gt;solar flare driver code&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://utcc.utoronto.ca/~cks/space/blog/linux/DecodingPageAllocFailures&quot;&gt;how to decode page allocation failure&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/7256969095984948104/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/03/linux-kernel-books.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7256969095984948104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7256969095984948104'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/03/linux-kernel-books.html' title='linux kernel books'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-2962632747992622692</id><published>2020-03-29T20:52:00.001-07:00</published><updated>2020-03-29T20:52:36.902-07:00</updated><title type='text'>How to tune the Linux kernel for memory performance</title><content type='html'>&lt;a href=&quot;https://discuss.aerospike.com/t/how-to-tune-the-linux-kernel-for-memory-performance/4195&quot;&gt;How to tune the Linux kernel for memory performance&lt;/a&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;posts-wrapper&quot; style=&quot;-webkit-font-smoothing: subpixel-antialiased; position: relative;&quot;&gt;
&lt;div class=&quot;ember-view&quot; id=&quot;ember37&quot;&gt;
&lt;div class=&quot;post-stream&quot;&gt;
&lt;div class=&quot;topic-post clearfix topic-owner regular&quot; style=&quot;border-left-color: transparent; border-left-style: solid; border-left-width: 1px;&quot;&gt;
&lt;article class=&quot;boxed onscreen-post&quot; data-post-id=&quot;11717&quot; data-topic-id=&quot;4195&quot; data-user-id=&quot;766&quot; id=&quot;post_1&quot; style=&quot;height: 3344.5px; position: relative;&quot;&gt;&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;topic-body clearfix&quot; style=&quot;border-top-color: rgb(233, 233, 233); border-top-style: solid; border-top-width: 1px; float: left; padding: 12px 0px 0px; position: relative; width: calc(712px);&quot;&gt;
&lt;div class=&quot;regular contents&quot; style=&quot;margin-top: 15px; position: relative;&quot;&gt;
&lt;div class=&quot;cooked&quot; style=&quot;line-height: 1.4; overflow: hidden; padding: 0px 11px 0.25em; word-wrap: break-word;&quot;&gt;
&lt;h1 style=&quot;font-size: 1.5157em; line-height: 1.2; margin: 0px 0px 10px;&quot;&gt;
How to tune the Linux kernel for memory performance&lt;/h1&gt;
&lt;h2 style=&quot;font-size: 1.3195em; line-height: 1.2; margin: 30px 0px 10px;&quot;&gt;
Context&lt;/h2&gt;
The linux kernel attempts to optimize RAM utilization, in that it occupies unused RAM with caches. This is done on the basis that unused RAM is wasted RAM.&lt;br /&gt;
Over time the kernel will fill the RAM with cache. As more memory is required by the applications/buffers, the kernel goes through the cache memory pages and finds a block large enough to fit the requested malloc. It then frees that memory and allocates it to the calling application.&lt;br /&gt;
Under some circumstances, this can affect the general performance of the system as cache de-allocation is time-consuming in comparison with access to unused RAM. Higher latency could therefore sometimes be observed.&lt;br /&gt;
This latency will purely be based on the fact that RAM is being used to its full speed potential. As such, no other symptoms may occur apart from general overall and potentially sporadic latency increases. The equivalent would be similar to symptoms that may be observed if the hard disks are not keeping up with reads and writes. The latency may also affect either Aerospike, or operating system components, such as network card/iptables/ebtables/iproute2 mallocs. As such this may show network-based latency instead. The following article discusses this further and provides steps to minimize impact on the system.&lt;br /&gt;
&lt;h2 style=&quot;font-size: 1.3195em; line-height: 1.2; margin: 30px 0px 10px;&quot;&gt;
Explanation&lt;/h2&gt;
The kernel memory cache contains the following:&lt;br /&gt;
&lt;ul style=&quot;clear: both; margin: 0px; padding: 0px 0px 0px 40px;&quot;&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;dirty cache&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;- Data blocks not yet committed to the file systems which support caching (e.g. ext4). This can be emptied by issuing the&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;sync&lt;/code&gt;&amp;nbsp;command athough this may imply a periodic performance penalty. This is not advised for normal usage unless it is extremely important to commit data to hard drive (for example when expecting a failure).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;clean cache&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;- Data blocks which are on the hard drive but are also retained in memory for fast access. Dropping the clean cache can result in a performance deficit as all data will read from disk, whereas beforehand, the frequently used data would be fetched directly from RAM.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;inode cache&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;- Cache of the inode location information. This can be dropped as with clean cache but with the attendant performance penalty.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;slab cache&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;- This type of cache stores objects allocated via malloc by applications so that they may be re-malloc again in the future with object data already populated, resulting in speed gain during memory allocations.&lt;/li&gt;
&lt;/ul&gt;
While not much can be done with&amp;nbsp;&lt;em&gt;dirty cache&lt;/em&gt;, the other cached objects can be cleared. This has potentially 2 outcomes. Latency in high-malloc applications, such as Aerospike when storing data in memory, will be reduced. On the other hand, disk access may slow down, as all data will have to be read from disk.&lt;br /&gt;
Clearing&amp;nbsp;&lt;em&gt;slab cache&lt;/em&gt;&amp;nbsp;on a server can potentially introduce a temporary speed penalty (spike). For this reason, it is not advised to clear caches. Instead, it is preferred to inform the system that a certain amount of RAM should never be occupied by cache.&lt;br /&gt;
If necessary, clearing the cache can be performed as follows:&lt;br /&gt;
&lt;pre style=&quot;font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; overflow: auto;&quot;&gt;&lt;code class=&quot;hljs ruby&quot; style=&quot;background-color: #f9f9f9; color: #333333; display: block; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; max-height: 500px; overflow: auto; padding: 0.5em; tab-size: 4; word-wrap: normal;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;color: #999988; font-style: italic;&quot;&gt;# clear page cache (above type 2 and 3)&lt;/span&gt;
$ echo &lt;span class=&quot;hljs-number&quot; style=&quot;color: #009999;&quot;&gt;1&lt;/span&gt; &amp;gt; &lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/proc/sys&lt;/span&gt;&lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/vm/drop&lt;/span&gt;_caches

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: #999988; font-style: italic;&quot;&gt;# clear slab cache (above type 4)&lt;/span&gt;
$ echo &lt;span class=&quot;hljs-number&quot; style=&quot;color: #009999;&quot;&gt;2&lt;/span&gt; &amp;gt; &lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/proc/sys&lt;/span&gt;&lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/vm/drop&lt;/span&gt;_caches

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: #999988; font-style: italic;&quot;&gt;# clear page and slab cache (types 2,3,4)&lt;/span&gt;
$ echo &lt;span class=&quot;hljs-number&quot; style=&quot;color: #009999;&quot;&gt;3&lt;/span&gt; &amp;gt; &lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/proc/sys&lt;/span&gt;&lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/vm/drop&lt;/span&gt;_caches
&lt;/code&gt;&lt;/pre&gt;
Most of the space will be occupied by&amp;nbsp;&lt;em&gt;page cache&lt;/em&gt;, not&amp;nbsp;&lt;em&gt;slab cache&lt;/em&gt;. It is recommended that when clearing cache, to only drop the page cache (&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;echo 1&lt;/code&gt;).&lt;br /&gt;
For a more permanent fix, a minimum number of free RAM can be set for the kernel. Consider the following example:&lt;br /&gt;
&lt;pre style=&quot;font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; overflow: auto;&quot;&gt;&lt;code class=&quot;hljs makefile&quot; style=&quot;background-color: #f9f9f9; color: #333333; display: block; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; max-height: 500px; overflow: auto; padding: 0.5em; tab-size: 4; word-wrap: normal;&quot;&gt;Total RAM: 100GB
&lt;span class=&quot;hljs-section&quot;&gt;Used: 10GB&lt;/span&gt;
&lt;span class=&quot;hljs-section&quot;&gt;Buffers: 40GB&lt;/span&gt;
Minimum free: 10GB
&lt;span class=&quot;hljs-section&quot;&gt;Cache: 40GB&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
In this example, there is 10GB free memory selected using the&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;minimum free&lt;/code&gt;&amp;nbsp;option. In such a case, if 5GB of memory is allocated for buffers, the kernel will allow the allocation to happen instantly. It will then de-allocate some cache to ensure 10GB free memory. Allocations will happen instantly and cache will be dynamically shrunk to ensure that 10GB remains free at all times. The new allocation would look as follows:&lt;br /&gt;
&lt;pre style=&quot;font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; overflow: auto;&quot;&gt;&lt;code class=&quot;hljs makefile&quot; style=&quot;background-color: #f9f9f9; color: #333333; display: block; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; max-height: 500px; overflow: auto; padding: 0.5em; tab-size: 4; word-wrap: normal;&quot;&gt;Total RAM: 100GB
&lt;span class=&quot;hljs-section&quot;&gt;Used: 10GB&lt;/span&gt;
&lt;span class=&quot;hljs-section&quot;&gt;Buffers: 45GB&lt;/span&gt;
Minimum free: 10GB
&lt;span class=&quot;hljs-section&quot;&gt;Cache: 35GB&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
Fine-tuning these parameters is dependant upon the current utilization. For Aerospike, it should be at least 1.1GB free in&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;min_free_kbytes&lt;/code&gt;, if the available system memory allows. This means that caches will still operate sufficiently, while leaving a margin for applications to allocate into.&lt;br /&gt;
&lt;pre style=&quot;font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; overflow: auto;&quot;&gt;&lt;code class=&quot;hljs ruby&quot; style=&quot;background-color: #f9f9f9; color: #333333; display: block; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; max-height: 500px; overflow: auto; padding: 0.5em; tab-size: 4; word-wrap: normal;&quot;&gt;$ cat /proc/sys/vm/min_free_kbytes
&lt;span class=&quot;hljs-number&quot; style=&quot;color: #009999;&quot;&gt;67584&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
Tuning is performed by performing an&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;echo NUMBER &amp;gt; /proc/sys/vm/min_free_kbytes&lt;/code&gt;&amp;nbsp;where, NUMBER is the number of kilobytes required to be free in the system. To leave 3% of memory on a 100GB RAM machine unoccupied, the command would be:&lt;br /&gt;
&lt;pre style=&quot;font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; overflow: auto;&quot;&gt;&lt;code class=&quot;hljs ruby&quot; style=&quot;background-color: #f9f9f9; color: #333333; display: block; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; max-height: 500px; overflow: auto; padding: 0.5em; tab-size: 4; word-wrap: normal;&quot;&gt;echo &lt;span class=&quot;hljs-number&quot; style=&quot;color: #009999;&quot;&gt;3145728&lt;/span&gt; &amp;gt; &lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/proc/sys&lt;/span&gt;&lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/vm/min&lt;/span&gt;_free_kbytes
&lt;/code&gt;&lt;/pre&gt;
Caution should be exercised when setting this parameter, both too low and too high values can have an adverse effect upon system performance. Setting&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;min_free_kbytes&lt;/code&gt;&amp;nbsp;too low prevents the system from reclaiming memory. This can result in system hangs and OOM kills of processes.&lt;br /&gt;
Setting this parameter to a value that is too high (5-10% of total system memory) will cause the system to run out of memory immediately. Linux is designed to use all available RAM to cache file system data. Setting a high&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;min_free_kbytes&lt;/code&gt;&amp;nbsp;value results in the system spending too much time reclaiming memory.&lt;br /&gt;
The&amp;nbsp;&lt;a href=&quot;https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/performance_tuning_guide/s-memory-tunables&quot; style=&quot;color: #c2171d; cursor: pointer; text-decoration: none; word-wrap: break-word;&quot;&gt;standard recommendation&amp;nbsp;&lt;span class=&quot;badge badge-notification clicks&quot; style=&quot;background-color: #e9e9e9; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; border: none; color: #919191; display: inline-block; font-size: 0.7579em; line-height: 1; min-width: 0.5em; padding: 0.21em 0.42em; position: relative; text-align: center; top: -1px; white-space: nowrap;&quot; title=&quot;131 clicks&quot;&gt;131&lt;/span&gt;&lt;/a&gt;&amp;nbsp;would be to keep&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;min_free_kbytes&lt;/code&gt;&amp;nbsp;at 1-3% of the total memory on the system.&lt;br /&gt;
It is advised to either reduce swappiness to 0 or not use swap. For low-latency operations, using swap to any extent will drastically slow down performance.&lt;br /&gt;
To set the swappiness to 0 to reduce potential latency:&lt;br /&gt;
&lt;pre style=&quot;font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; overflow: auto;&quot;&gt;&lt;code class=&quot;hljs ruby&quot; style=&quot;background-color: #f9f9f9; color: #333333; display: block; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; max-height: 500px; overflow: auto; padding: 0.5em; tab-size: 4; word-wrap: normal;&quot;&gt;echo &lt;span class=&quot;hljs-number&quot; style=&quot;color: #009999;&quot;&gt;0&lt;/span&gt; &amp;gt; &lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/proc/sys&lt;/span&gt;&lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #009900;&quot;&gt;/vm/swappiness&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 style=&quot;font-size: 1.3195em; line-height: 1.2; margin: 30px 0px 10px;&quot;&gt;
Notes&lt;/h2&gt;
IMPORTANT: Any and all changes above are NOT permanent. They only happen during machine runtime. To make the changes permanent, additions must be made to&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;/etc/sysctl.conf&lt;/code&gt;.&lt;br /&gt;
The following lines make the changes shown above permanent:&lt;br /&gt;
&lt;pre style=&quot;font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; overflow: auto;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-color: #f9f9f9; color: #333333; display: block; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; max-height: 500px; overflow: auto; padding: 0.5em; tab-size: 4; word-wrap: normal;&quot;&gt;vm.min_free_kbytes = 5248000
vm.swappiness = 0
&lt;/code&gt;&lt;/pre&gt;
As always, editing such parameters can be destructive if done incorrectly. It is recommended to perform the changes in a lab environment before moving to production. Making changes dynamically before performing permanent change helps in mitigating any potential side effects which could occur.&lt;br /&gt;
There is another parameter aimed at a similar output as the above, called&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;zone_reclaim&lt;/code&gt;. Unfortunately, this parameter causes aggressive reclaims and scans and should therefore be disabled. This is disabled as standard on all newer kernels and distributions.&lt;br /&gt;
The following command can be used to ensure that&amp;nbsp;&lt;code style=&quot;background-color: #f8f8f8; color: #333333; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em;&quot;&gt;zone_reclaim&lt;/code&gt;&amp;nbsp;is disabled:&lt;br /&gt;
&lt;pre style=&quot;font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; overflow: auto;&quot;&gt;&lt;code class=&quot;hljs ruby&quot; style=&quot;background-color: #f9f9f9; color: #333333; display: block; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; max-height: 500px; overflow: auto; padding: 0.5em; tab-size: 4; word-wrap: normal;&quot;&gt;$ sysctl -a &lt;span class=&quot;hljs-params&quot;&gt;|grep zone_reclaim_mode
vm.zone_reclaim_mode = 0
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 style=&quot;font-size: 1.3195em; line-height: 1.2; margin: 30px 0px 10px;&quot;&gt;
Keywords&lt;/h2&gt;
KERNEL MEMORY CACHE DROP_CACHES MIN_FREE_KBYTES SWAPPINESS&lt;br /&gt;
&lt;h2 style=&quot;font-size: 1.3195em; line-height: 1.2; margin: 30px 0px 10px;&quot;&gt;
Timestamp&lt;/h2&gt;
June 2 2019&lt;/div&gt;
&lt;section class=&quot;post-menu-area clearfix&quot; style=&quot;margin: 20px 0px; padding-left: 11px; position: relative;&quot;&gt;&lt;nav class=&quot;post-controls clearfix expanded&quot; style=&quot;padding: 0px;&quot;&gt;&lt;div class=&quot;actions&quot; style=&quot;display: inline-block; float: right; text-align: right;&quot;&gt;
&lt;div class=&quot;double-button&quot; style=&quot;color: #bdbdbd; display: inline-flex; margin-right: 0.15em;&quot;&gt;
&lt;button aria-label=&quot;like this post&quot; class=&quot;widget-button btn-flat toggle-like like no-text btn-icon&quot; style=&quot;background-color: transparent; border: none; color: #bdbdbd; cursor: pointer; font-family: inherit; font-size: 1.1487em; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: 1; margin: 0px; outline: 0px; overflow: visible; padding: 8px 10px; transition: color 0.25s, background 0.25s; vertical-align: top;&quot; title=&quot;like this post&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;fa d-icon d-icon-d-unliked svg-icon svg-node&quot;&gt;&lt;use xlink:href=&quot;#far-heart&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;
&lt;button aria-label=&quot;share a link to this post&quot; class=&quot;widget-button btn-flat share no-text btn-icon&quot; data-post-number=&quot;1&quot; data-share-url=&quot;/t/how-to-tune-the-linux-kernel-for-memory-performance/4195&quot; style=&quot;background-color: transparent; border: none; color: #bdbdbd; cursor: pointer; font-family: inherit; font-size: 1.1487em; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: 1; margin: 0px 2px 0px 3px; outline: 0px; overflow: visible; padding: 8px 10px; transition: color 0.25s, background 0.25s; vertical-align: top;&quot; title=&quot;share a link to this post&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;fa d-icon d-icon-link svg-icon svg-node&quot;&gt;&lt;use xlink:href=&quot;#link&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;
&lt;/nav&gt;&lt;/section&gt;&lt;/div&gt;
&lt;section class=&quot;post-actions&quot; style=&quot;-webkit-user-select: none; clear: both; margin-bottom: 10px; text-align: right;&quot;&gt;&lt;/section&gt;&lt;div class=&quot;post-links-container&quot; style=&quot;-webkit-user-select: none; clear: both; margin-left: 11px;&quot;&gt;
&lt;ul class=&quot;post-links&quot; style=&quot;border-top-color: rgb(233, 233, 233); border-top-style: solid; border-top-width: 1px; list-style: none; margin: 1em 0px 0px; padding: 1em 0px 0px;&quot;&gt;
&lt;li style=&quot;margin-bottom: 0.5em;&quot;&gt;&lt;a class=&quot;track-link inbound&quot; href=&quot;https://discuss.aerospike.com/t/understanding-linux-memory-usage-reporting/4727&quot; style=&quot;align-items: center; color: #919191; cursor: pointer; display: flex; text-decoration: none;&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;fa d-icon d-icon-link svg-icon svg-node&quot;&gt;&lt;use xlink:href=&quot;#link&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;span style=&quot;overflow: hidden; text-overflow: ellipsis; white-space: nowrap;&quot;&gt;Understanding linux memory usage reporting&lt;/span&gt;&lt;span class=&quot;badge badge-notification clicks&quot; style=&quot;background-color: #e9e9e9; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; border: none; display: inline-block; flex: 0 0 auto; font-size: 0.7579em; line-height: 1; margin-left: 0.5em; min-width: 0.5em; padding: 0.21em 0.42em; position: relative; text-align: center; top: -1px; white-space: nowrap;&quot;&gt;30&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;margin-bottom: 0.5em;&quot;&gt;&lt;a class=&quot;track-link inbound&quot; href=&quot;https://discuss.aerospike.com/t/how-to-troubleshoot-oom-kills-on-systems-with-large-amount-of-cache-memory-allocated/6467&quot; style=&quot;align-items: center; color: #919191; cursor: pointer; display: flex; text-decoration: none;&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;fa d-icon d-icon-link svg-icon svg-node&quot;&gt;&lt;use xlink:href=&quot;#link&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;span style=&quot;overflow: hidden; text-overflow: ellipsis; white-space: nowrap;&quot;&gt;How to troubleshoot OOM kills on systems with large amount of cache memory allocated&lt;/span&gt;&lt;span class=&quot;badge badge-notification clicks&quot; style=&quot;background-color: #e9e9e9; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; border: none; display: inline-block; flex: 0 0 auto; font-size: 0.7579em; line-height: 1; margin-left: 0.5em; min-width: 0.5em; padding: 0.21em 0.42em; position: relative; text-align: center; top: -1px; white-space: nowrap;&quot;&gt;16&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;margin-bottom: 0.5em;&quot;&gt;&lt;a class=&quot;track-link inbound&quot; href=&quot;https://discuss.aerospike.com/t/vmxnet3-page-allocation-failure/5712&quot; style=&quot;align-items: center; color: #919191; cursor: pointer; display: flex; text-decoration: none;&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;fa d-icon d-icon-link svg-icon svg-node&quot;&gt;&lt;use xlink:href=&quot;#link&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;span style=&quot;overflow: hidden; text-overflow: ellipsis; white-space: nowrap;&quot;&gt;Vmxnet3 page allocation failure&lt;/span&gt;&lt;span class=&quot;badge badge-notification clicks&quot; style=&quot;background-color: #e9e9e9; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; border: none; display: inline-block; flex: 0 0 auto; font-size: 0.7579em; line-height: 1; margin-left: 0.5em; min-width: 0.5em; padding: 0.21em 0.42em; position: relative; text-align: center; top: -1px; white-space: nowrap;&quot;&gt;6&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;margin-bottom: 0.5em;&quot;&gt;&lt;a class=&quot;track-link inbound&quot; href=&quot;https://discuss.aerospike.com/t/how-to-tune-the-linux-os-for-aerospike-servers-best-practices/6466&quot; style=&quot;align-items: center; color: #919191; cursor: pointer; display: flex; text-decoration: none;&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;fa d-icon d-icon-link svg-icon svg-node&quot;&gt;&lt;use xlink:href=&quot;#link&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;span style=&quot;overflow: hidden; text-overflow: ellipsis; white-space: nowrap;&quot;&gt;How To Tune the linux OS for Aerospike servers - best practices&lt;/span&gt;&lt;span class=&quot;badge badge-notification clicks&quot; style=&quot;background-color: #e9e9e9; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; border: none; display: inline-block; flex: 0 0 auto; font-size: 0.7579em; line-height: 1; margin-left: 0.5em; min-width: 0.5em; padding: 0.21em 0.42em; position: relative; text-align: center; top: -1px; white-space: nowrap;&quot;&gt;5&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;margin-bottom: 1em;&quot;&gt;&lt;a class=&quot;track-link inbound&quot; href=&quot;https://discuss.aerospike.com/t/broken-pipe-errors-and-apparently-random-migrations-and-a-fix/6298&quot; style=&quot;align-items: center; color: #919191; cursor: pointer; display: flex; text-decoration: none;&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;fa d-icon d-icon-link svg-icon svg-node&quot;&gt;&lt;use xlink:href=&quot;#link&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;span style=&quot;overflow: hidden; text-overflow: ellipsis; white-space: nowrap;&quot;&gt;Broken pipe errors and apparently random migrations (and a fix)&lt;/span&gt;&lt;span class=&quot;badge badge-notification clicks&quot; style=&quot;background-color: #e9e9e9; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; border: none; display: inline-block; flex: 0 0 auto; font-size: 0.7579em; line-height: 1; margin-left: 0.5em; min-width: 0.5em; padding: 0.21em 0.42em; position: relative; text-align: center; top: -1px; white-space: nowrap;&quot;&gt;1&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/article&gt;&lt;div class=&quot;widget-connector&quot;&gt;
&lt;div class=&quot;ember-view&quot; id=&quot;ember79&quot;&gt;
&lt;div class=&quot;ember-view&quot; id=&quot;ember80&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;loading-container ember-view&quot; id=&quot;ember38&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;
&lt;div class=&quot;loading-container ember-view&quot; id=&quot;ember39&quot; style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div id=&quot;topic-bottom&quot; style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;&quot;&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/2962632747992622692/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/03/how-to-tune-linux-kernel-for-memory.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2962632747992622692'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2962632747992622692'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/03/how-to-tune-linux-kernel-for-memory.html' title='How to tune the Linux kernel for memory performance'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-4161994599315000849</id><published>2020-03-29T20:48:00.001-07:00</published><updated>2020-04-03T20:23:33.575-07:00</updated><title type='text'>Linux network stack</title><content type='html'>&lt;br /&gt;
&lt;a href=&quot;https://epickrram.blogspot.com/2016/05/navigating-linux-kernel-network-stack.html&quot;&gt;Navigating the Linux kernel network stack: receive path&lt;/a&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.privateinternetaccess.com/blog/linux-networking-stack-from-the-ground-up-part-1/&quot;&gt;Linux networking from ground up&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;a href=&quot;https://wiki.linuxfoundation.org/networking/napi&quot; rel=&quot;nofollow&quot;&gt;NAPI&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/leandromoreira/linux-network-performance-parameters/blob/master/README.md&quot;&gt;linux network illustration&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blog.packagecloud.io/eng/2016/06/22/monitoring-tuning-linux-networking-stack-receiving-data/#udp_rcv&quot;&gt;Monitor and tuning linux network &lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 id=&quot;background&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
Background&lt;/h2&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;At&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://lmax.com/&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;work&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;we practice continuous integration in terms of&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://epickrram.blogspot.co.uk/2014/05/performance-testing-at-lmax-part-one.html&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;performance testing&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;alongside different stages of functional testing.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;In order to do this, we have a performance environment that fully replicates the hardware and software used in our production environments. This is necessary in order to be able to find the limits of our system in terms of throughput and latency, and means that we make sure that the environments are identical, right down to the network cables.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Since we like to be ahead of the curve, we are constantly trying to push the boundaries of our system to find out where it will fall over, and the nature of the failure mode.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;This involves&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://epickrram.blogspot.co.uk/2014/08/performance-testing-at-lmax-part-three.html&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;running production-like load&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;against the system at a much higher rate than we have ever seen in production. We currently aim to be able to handle a constant throughput of 2-5 times the maximum peak throughput ever observed in production. We believe that this will give us enough headroom to handle future capacity requirements.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Our Performance &amp;amp; Capacity team has a constant background task of:&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;increase load applied to the system until it breaks&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;find and fix the bottleneck&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Using this process, we aim to ensure that we are able to handle spikes in demand, and increases in user numbers, while still achieving a consistent and low latency-profile.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;There is actually a third step to this process, which is something like &#39;buy new hardware&#39; or &#39;modify the system to do less work&#39;, since there is only so much than tuning will buy you.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The code that is inspected in this article is that taken by inbound multicast traffic on Linux kernel version 4.0.&lt;/span&gt;&lt;br /&gt;
&lt;h2 id=&quot;identifying-a-bottleneck&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;identifying-a-bottleneck&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;identifying-a-bottleneck&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
Identifying a bottleneck&lt;/h2&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;During the latest iteration of the break/fix cycle, we identified one particular service as problematic. The service in question is one of those responsible for consuming the output of our matching engine, which can peak at 250,000 messages per second at our current performance-test load.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;When we have a bottleneck in one of our services, it usually follows a familiar pattern of back-pressure from the application processing thread, resulting in packets being dropped by the networking card.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;In this case however, we could see from our monitoring that we were not suffering from any processing back-pressure, so it was necessary to delve a little deeper into the network packet receive path in order to understand the problem.&lt;/span&gt;&lt;br /&gt;
&lt;h2 id=&quot;understanding-the-data-flow&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;understanding-the-data-flow&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;understanding-the-data-flow&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;understanding-the-data-flow&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
Understanding the data flow&lt;/h2&gt;
&lt;div style=&quot;border-top-color: rgb(238, 238, 238); border-top-style: solid; border-top-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; padding-top: 8px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;caret-color: rgb(68, 68, 68); clear: both; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-align: center;&quot;&gt;
&lt;a href=&quot;https://raw.githubusercontent.com/epickrram/blog-images/master/2016_04/SoftIRQProcessing.jpg&quot; imageanchor=&quot;1&quot; style=&quot;color: #4d469c; margin-left: 1em; margin-right: 1em; text-decoration: none;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;459&quot; src=&quot;https://raw.githubusercontent.com/epickrram/blog-images/master/2016_04/SoftIRQProcessing.jpg&quot; style=&quot;-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 0px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; border: 1px solid transparent; box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 0px; padding: 8px; position: relative;&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-align: center;&quot;&gt;
&lt;i&gt;Components involved in network packet receipt&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The Linux kernel provides a number of counters that can give an indication of any problems in the network stack. Since we are concerned with throughput, we will be most interested in things like queue depths and drop counts.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Before looking at the available statistics, let&#39;s take a look at how a packet is handled once it is pulled off the wire.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The journey begins in the network driver code; this is vendor-specific and in the majority of cases open source. In this example, we&#39;re working with an Intel 10Gb card, which uses the ixgbe driver. You can find out the driver used by a network interface by using&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ethtool&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;ethtool -i &amp;lt;device-name&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;This will generate output that looks something like:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;driver: ixgbe
version: 3.19.1-k
firmware-version: 0x546d0001
bus-info: 0000:41:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no&lt;/code&gt;&lt;/pre&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The driver code can be found in the Linux kernel source&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/drivers/net/ethernet/intel/ixgbe/?v=4.0&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;h3 id=&quot;napi&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;napi&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;napi&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;napi&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
NAPI&lt;/h3&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;NAPI, or New API is a mechanism introduced into the kernel several years ago. More background can be read&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.linuxfoundation.org/collaborate/workgroups/networking/napi&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;, but in summary, NAPI increases network receive performance by changing packet receipt from interrupt-driven to polling-mode.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Previous to the introduction of NAPI, network cards would typically fire a hardware interrupt for each received packet. Since an interrupt on a CPU will always cause suspension of the executing software, a high interrupt rate can interfere with software performance. NAPI addresses this by exposing a poll method to the kernel, which is periodically executed (actually via an interrupt). While the poll method is executing, receive interrupts for the network device are disabled. The effect of this is that the kernel can drain potentially multiple packets from the network device receive buffer, thus increasing throughput at the same time as reducing the interrupt overhead.&lt;/span&gt;&lt;br /&gt;
&lt;h3 id=&quot;interrupt-handling&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;interrupt-handling&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;interrupt-handling&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;interrupt-handling&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
Interrupt handling&lt;/h3&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;When the network device driver is initially configured, it first associates a handler function with the receive interrupt. This function will be invoked whenever the CPU receives a hardware interrupt from the network card.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;For the card that we&#39;re looking at, this happens in a method called&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c?v=4.0#L2740&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;ixgbe_request_msix_irqs&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;request_irq(entry-&amp;gt;vector, &amp;amp;ixgbe_msix_clean_rings, 0,
   q_vector-&amp;gt;name, q_vector);&lt;/code&gt;&lt;/pre&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;So when an interrupt is received by the CPU, the ixgbe_msix_clean_rings method simply&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c?v=4.0#L2675&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;schedules a NAPI poll&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;, and returns IRQ_HANDLED:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
{
    struct ixgbe_q_vector *q_vector = data;
    ...
    if (q_vector-&amp;gt;rx.ring || q_vector-&amp;gt;tx.ring)
        napi_schedule(&amp;amp;q_vector-&amp;gt;napi);

    return IRQ_HANDLED;
}&lt;/code&gt;&lt;/pre&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Scheduling the NAPI poll entails&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/dev.c?v=4.0#L3022&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;adding some work&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;to the per-cpu poll list maintained in the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softnet_data&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;structure:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;static inline void ____napi_schedule(struct softnet_data *sd,
                                     struct napi_struct *napi)
{
    list_add_tail(&amp;amp;napi-&amp;gt;poll_list, &amp;amp;sd-&amp;gt;poll_list);
    __raise_softirq_irqoff(NET_RX_SOFTIRQ);
}&lt;/code&gt;&lt;/pre&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;and then raising a&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;event. Once the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;event has been raised, the driver knows that the poll function will be called in the near future.&lt;/span&gt;&lt;br /&gt;
&lt;h3 id=&quot;softirq-processing&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;softirq-processing&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;softirq-processing&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;softirq-processing&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
softirq processing&lt;/h3&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;For more background on interrupt handling, the&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://lwn.net/Kernel/LDD3/&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;Linux Device Drivers&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;book has a chapter dedicated to this topic. Suffice to say, doing work inside of a hardware interrupt context is generally avoided within the kernel; while handling a hardware interrupt a CPU is not executing user or kernel software threads, and no other hardware interrupts can be handled until the current routine is complete. One mechanism for dealing with this is to use&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softirqs&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Each CPU in the system has a bound process called&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirqd/&amp;lt;cpu_number&amp;gt;&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;, which is responsible for processing&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;events.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;In this manner, when a hardware interrupt is received, the driver raises a softIRQ to be processed on the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirqd&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;process. So it is this process that will be responsible for calling the driver&#39;s&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;poll&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;method.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;handler&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/dev.c?v=4.0#L7475&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;&lt;code&gt;net_rx_action&lt;/code&gt;&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;is configured for network packet receive events during device initialisation. All&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;events of type&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;NET_RX_SOFTIRQ&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;will be handled by the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;net_rx_action&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;function.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;So, having followed the code this far, we can say that when a network packet is in the device&#39;s receive ring-buffer, the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;net_rx_action&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;function will be the top-level entry point for packet processing.&lt;/span&gt;&lt;br /&gt;
&lt;h3 id=&quot;net_rx_action&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;net_rx_action&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;net_rx_action&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;net_rx_action&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
net_rx_action&lt;/h3&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;At this point, it is instructive to look at a function trace of the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirqd&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;process. This trace was generated using&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://www.kernel.org/doc/Documentation/trace/ftrace.txt&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;&lt;code&gt;ftrace&lt;/code&gt;&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;, and gives a high-level overview of the functions involved in processing the available packets on the network device.&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;net_rx_action() {
  ixgbe_poll() {
    ixgbe_clean_tx_irq();
    ixgbe_clean_rx_irq() {
      ixgbe_fetch_rx_buffer() {
        ... // allocate buffer for packet
      } // returns the buffer containing packet data
      ... // housekeeping
      napi_gro_receive() {
        // generic receive offload
        dev_gro_receive() {
          inet_gro_receive() {
            udp4_gro_receive() {
              udp_gro_receive();
            }
          }
        }
        netif_receive_skb_internal() {
          __netif_receive_skb() {
            __netif_receive_skb_core() {
              ...
              ip_rcv() {
                ...
                ip_rcv_finish() {
                  ...
                  ip_local_deliver() {
                    ip_local_deliver_finish() {
                      raw_local_deliver();
                      udp_rcv() {
                        __udp4_lib_rcv() {
                          __udp4_lib_mcast_deliver() {
                            ...
                            // clone skb &amp;amp; deliver
                            flush_stack() {
                              udp_queue_rcv_skb() {
                                ... // data preparation
                                // &lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1497&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;deliver UDP packet&lt;/a&gt;
                                // &lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1584&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;check if buffer is full&lt;/a&gt;
                                __udp_queue_rcv_skb() {
                                  // &lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1453&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;deliver to socket queue&lt;/a&gt;
                                  // &lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1464&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;check for delivery error&lt;/a&gt;
                                  sock_queue_rcv_skb() {
                                    ...
                                    _raw_spin_lock_irqsave();
                                    // &lt;a href=&quot;http://lxr.free-electrons.com/source/include/linux/skbuff.h?v=4.0#L1481&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;enqueue packet to socket buffer list&lt;/a&gt;
                                    _raw_spin_unlock_irqrestore();
                                    // &lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/sock.c?v=4.0#L474&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;wake up listeners&lt;/a&gt;
                                    sock_def_readable() {
                                      __wake_up_sync_key() {
                                        _raw_spin_lock_irqsave();
                                        __wake_up_common() {
                                          ep_poll_callback() {
                                            ...
                                            _raw_spin_unlock_irqrestore();
                                          }
                                        }
                                        _raw_spin_unlock_irqrestore();
                                      }
...&lt;/code&gt;&lt;/pre&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;handler performs the following steps:&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Call the driver&#39;s poll method (in this case&amp;nbsp;&lt;code&gt;ixgbe_poll&lt;/code&gt;)&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Perform some&amp;nbsp;&lt;a href=&quot;https://lwn.net/Articles/358910/&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;GRO&lt;/a&gt;&amp;nbsp;functions to group packets together into a larger work unit&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Call the packet type&#39;s&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/dev.c?v=4.0#L1735&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;handler function&lt;/a&gt;&amp;nbsp;(&lt;code&gt;ip_rcv&lt;/code&gt;) to walk down the protocol chain&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Parse IP headers, perform checksumming then call&amp;nbsp;&lt;code&gt;ip_rcv_finish&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;The buffer&#39;s destination function is invoked, in this case&amp;nbsp;&lt;code&gt;udp_rcv&lt;/code&gt;&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Since these are multicast packets,&amp;nbsp;&lt;code&gt;__udp4_lib_mcast_deliver&lt;/code&gt;&amp;nbsp;is called&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;The packet is copied and delivered to each registered UDP socket queue&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;In&amp;nbsp;&lt;code&gt;udp_queue_rcv_skb&lt;/code&gt;, buffers are checked and if space remains, the skb is added to the end of the socket&#39;s queue&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;monitoring-back-pressure&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;monitoring-back-pressure&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;monitoring-back-pressure&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;monitoring-back-pressure&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
Monitoring back-pressure&lt;/h2&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;When attempting to increase the throughput of an application, we need to understand where back-pressure is coming from.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;At this point in the data receive path, we could have throughput issues for two reasons:&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;The&amp;nbsp;&lt;code&gt;softirq&lt;/code&gt;&amp;nbsp;handling mechanism cannot dequeue packets from the network device fast enough&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;The application processing the destination socket is not dequeuing packets from the socket buffer fast enough&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;softirq-back-pressure&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;softirq-back-pressure&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;softirq-back-pressure&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;softirq-back-pressure&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
softirq back-pressure&lt;/h3&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;For the first case, we need to look at softnet stats (&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;/proc/net/softnet_stat&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;), which are maintained by the network receive stack.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The softnet stats are defined&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/include/linux/netdevice.h?v=4.0#L2444&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;as the per-cpu struct&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softnet_data&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;, which contains a few fields of interest:&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;processed&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;time_squeeze&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;dropped&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;processed&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;is the total number of packets processed, so is a good indicator of total throughput.&lt;/span&gt;&lt;br /&gt;
&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;time_squeeze&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;is updated if the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;process cannot process all packets available in the network device ring-buffer before its cpu-time is up. The process is limited to 2 jiffies of processing time, or a certain amount of &#39;work&#39;.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;There are a couple of sysctls that control these parameters:&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;code&gt;net.core.netdev_budget&lt;/code&gt;&amp;nbsp;- the total amount of processing to be done in one invocation of net_rx_action&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;code&gt;net.core.dev_weight&lt;/code&gt;&amp;nbsp;- an indicator to the network driver of how much work to do per invocation of its napi poll method&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;daemon will continue to&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/dev.c?v=4.0#L4655&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;call&amp;nbsp;&lt;code&gt;napi_poll&lt;/code&gt;&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;until either the time has run out, or the amount of work reported as completed by the driver exceeds the value of&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;net.core.netdev_budget&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;This behaviour will be driver-specific; in the Intel 10Gb driver, completed work will always be&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c?v=4.0#L2727&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;reported as&amp;nbsp;&lt;code&gt;net.core.dev_weight&lt;/code&gt;&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;if there are still packets to be processed at the end of a poll invocation.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Given some example numbers, we can determine how many times the napi_poll function will be called for a&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softIRQ&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;event:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;net.core.netdev_budget = 300
net.core.dev_weight = 64

poll_count = (300 / 64) + 1 =&amp;gt; 5&lt;/code&gt;&lt;/pre&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;If there are still packets to be processed in the network device ring-buffer, then the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;time_squeeze&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;counter will be incremented for the given CPU.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;dropped&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;counter is only used when the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;process is attemping to add a packet to the backlog queue of another CPU. This can happen if&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://www.kernel.org/doc/Documentation/networking/scaling.txt&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;Receive Packet Steering&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;is enabled, but since we are only looking at UDP multicast without RPS, I won&#39;t go into the detail.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;So if our kernel helper thread is unable to move packets from the network device receive queue to the socket&#39;s receive buffer fast enough, we can expect the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;time_squeeze&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;column in&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;/proc/net/softnet_stat&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;to increase over time.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;In order to interpret the file, it is worth looking at&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/net-procfs.c?v=4.0#L146&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;the implementation&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;. Each row represents a CPU-local instance of the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;softnet_stat&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;struct (starting with CPU0 at the top), and the third column is the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;time_squeeze&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;entry.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The only tunable that we have at our disposal is the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;netdev_budget&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;value. Increasing this will allow the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;process to do more work. The process will still be limited by a total processing time of 2 jiffies though, so there will be an upper ceiling to packet throughput.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Given the speeds that modern processors are capable of, it is unlikely that the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;daemon will be unable to keep up with the flow of data, if properly configured.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;In order to give the kernel the best chance to do so, make sure that there is no contention for CPU resources by assigning network interrupts to a number of cores, and then using&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/Documentation/cgroups/cpusets.txt?v=4.0#L395&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;isolcpus&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;to make sure that no other processes will be running on them. This will give the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;daemon the best chance of copying the inbound packets in a timely manner.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;If the&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ksoftirq&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;daemon is squeezed frequently enough, or is just unable to get CPU time, then the network device will be forced to drop packets from the wire. In this case, we can use ethtool to find the rx_missed_errors count:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;ethtool -S &amp;lt;device-name&amp;gt; | grep rx_missed
rx_missed_errors: 0&lt;/code&gt;&lt;/pre&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;alternatively, the same data can be found by looking at the following file:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;&lt;code&gt;/sys/class/net/&amp;lt;device-name&amp;gt;/statistics/rx_missed_errors&lt;/code&gt;&lt;/pre&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;For a full description of each of the statistics reported by&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;ethtool&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;, refer to&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/Documentation/ABI/testing/sysfs-class-net-statistics&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;this document&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;h3 id=&quot;application-back-pressure&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;application-back-pressure&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;application-back-pressure&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;application-back-pressure&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;
Application back-pressure&lt;/h3&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;It is far more likely that our user programs will be the bottleneck here, and in order to determine whether that is the case, we need to look at the next stage in the message receipt path. A continuation of this post will explore that area in more detail.&lt;/span&gt;&lt;br /&gt;
&lt;h2 id=&quot;summary&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;summary&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;summary&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;summary&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
Summary&lt;/h2&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;For UDP-multicast traffic, we have seen in detail the code paths involved in moving an inbound network packet from a network device to a socket&#39;s input buffer. This stage can be broadly summarised as follows:&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;On packet receipt, the network device fires a hardware interrupt to the configured CPU&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;The hardware interrupt handler schedules a&amp;nbsp;&lt;code&gt;softIRQ&lt;/code&gt;&amp;nbsp;on the same CPU&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;The&amp;nbsp;&lt;code&gt;softIRQ&lt;/code&gt;&amp;nbsp;handler thread (&lt;code&gt;ksoftirqd&lt;/code&gt;) will disable receive interrupts and poll the card for received data&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Data will be copied from the network device&#39;s receive buffer into the destination socket&#39;s input buffer&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;After a certain amount of work has been done, or no inbound packets remain, the&amp;nbsp;&lt;code&gt;ksoftirq&lt;/code&gt;&amp;nbsp;daemon will re-enable receive interrupts and return&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;In order to optimise for throughput, there are a couple of things to try tuning:&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Increase the amount of work that the&amp;nbsp;&lt;code&gt;ksoftirq&lt;/code&gt;&amp;nbsp;daemon is allowed to do (&lt;code&gt;net.core.netdev_budget&lt;/code&gt;)&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Make sure that the&amp;nbsp;&lt;code&gt;ksoftirq&lt;/code&gt;&amp;nbsp;daemon is not contending for CPU resource or being descheduled due to other hardware interrupts&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;Increase the size of the network device&#39;s ring-buffer (&lt;code&gt;ethtool -g &amp;lt;device-name&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;As with all performance-related experiments, never attempt to tune the system without being able to measure the impact of any changes in isolation.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;First, make sure that you know what the problem is (i.e.&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;rx_missed_errors&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;or&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-size: 13px;&quot;&gt;time_squeeze&lt;/code&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;is increasing), the add the relevant monitoring. For this particular case, we would want to be able to correlate the application experiencing message loss with a change in the relevant counters, so recording and charting the numbers would be a good start.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Once this has been done, changes can be made to system configuration to see if an improvement can be made.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;Lastly, any changes to the tuning parameters that I&#39;ve mentioned MUST be configured via automation. We have sadly lost a fair amount of time to manual changes being made on machines that have not persisted across reboots.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;It is all too easy (and I speak as a repeat offender) to make adjustments, find the optimal configuration, and then move on to something else. Do yourself and your colleagues a favour and automate configuration management!&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;b style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&lt;/span&gt;&lt;b style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;Resources&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;I read lots of really useful documents while learning about this area of the kernel. Here are a few of them:&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;a href=&quot;https://www.coverfire.com/articles/queueing-in-the-linux-network-stack/&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;https://www.coverfire.com/articles/queueing-in-the-linux-network-stack/&lt;/a&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;a href=&quot;https://access.redhat.com/sites/default/files/attachments/20150325_network_performance_tuning.pdf&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;https://access.redhat.com/sites/default/files/attachments/20150325_network_performance_tuning.pdf&lt;/a&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;a href=&quot;https://www.kernel.org/doc/Documentation/networking/scaling.txt&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;https://www.kernel.org/doc/Documentation/networking/scaling.txt&lt;/a&gt;&lt;br /&gt;
&lt;br style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;&quot; /&gt;
&lt;a href=&quot;https://wiki.openwrt.org/doc/networking/praxis&quot; style=&quot;color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; text-decoration: none;&quot;&gt;https://wiki.openwrt.org/doc/networking/praxis&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 class=&quot;post-title entry-title&quot; itemprop=&quot;name&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 22px; font-stretch: normal; line-height: normal; margin: 0px; position: relative;&quot;&gt;
Navigating the Linux kernel network stack: into user land&lt;/h3&gt;
&lt;div class=&quot;post-header&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 1.6; margin: 0px 0px 1em;&quot;&gt;
&lt;div class=&quot;post-header-line-1&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;post-body entry-content&quot; id=&quot;post-body-7012364143023049082&quot; itemprop=&quot;description articleBody&quot; style=&quot;caret-color: rgb(68, 68, 68); color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 1.4; position: relative; width: 746px;&quot;&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
This is a continuation of my&amp;nbsp;&lt;a href=&quot;http://epickrram.blogspot.co.uk/2016/05/navigating-linux-kernel-network-stack.html&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;previous post&lt;/a&gt;, in which we follow the path of an inbound multicast packet to the user application.&lt;br /&gt;
At the end of the last post, I mentioned that application back-pressure was most likely to be the cause of receiver packet-loss. As we continue through the code path taken by inbound packets up into user-land, we will see the various points at which data will be discarded due to slow application processing, and what metrics can shed light on these events.&lt;br /&gt;
&lt;h2 id=&quot;protocol-mapping&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;protocol-mapping&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
Protocol mapping&lt;/h2&gt;
&lt;br /&gt;
First of all, let&#39;s take a quick look at how a received data packet is matched up to its&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/dev.c?v=4.0#L1735&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;handler function&lt;/a&gt;.&lt;br /&gt;
We can see from the stack-trace below that the top-level function calls when dealing with the packets are&amp;nbsp;&lt;code&gt;packet_rcv&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code&gt;ip_rcv:&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;__netif_receive_skb_core() {
    packet_rcv() {
        skb_push();
        __bpf_prog_run();
        consume_skb();
    }
    bond_handle_frame() {
        bond_3ad_lacpdu_recv();
    }
    packet_rcv() {
        skb_push();
        __bpf_prog_run();
        consume_skb();
    }
    packet_rcv() {
        skb_push();
        __bpf_prog_run();
        consume_skb();
    }
    ip_rcv() {
        ...&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
This trace captures the&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/dev.c?v=4.0#L3671&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;part of the receive path&lt;/a&gt;&amp;nbsp;where the inbound packet is passed to each registered handler function. In this way, the kernel handles things like VLAN tagging, interface bonding, and packet-capture. Note the&amp;nbsp;&lt;code&gt;__bpf_prog_run&lt;/code&gt;&amp;nbsp;function call, which indicates that this is the entry point for&amp;nbsp;&lt;code&gt;pcap&lt;/code&gt;&amp;nbsp;packet capture and filtering.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The protocol-to-handler mapping can be viewed in the file&amp;nbsp;&lt;code&gt;/proc/net/ptype&lt;/code&gt;:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;[pricem@metal]$ cat /proc/net/ptype 
Type Device      Function
ALL  em1      packet_rcv
0800          ip_rcv
0011          llc_rcv [llc]
0004          llc_rcv [llc]
88f5          mrp_rcv [mrp]
0806          arp_rcv
86dd          ipv6_rcv&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Comparing against&amp;nbsp;&lt;a href=&quot;https://en.wikipedia.org/wiki/EtherType#Notable_values&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;this reference&lt;/a&gt;, it is clear that the kernel reads the value of the ethernet frame&#39;s&amp;nbsp;&lt;code&gt;EtherType&lt;/code&gt;&amp;nbsp;field and dispatches to the corresponding function. There are also some functions that will be executed for all packet types (signified by type&amp;nbsp;&lt;code&gt;ALL&lt;/code&gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So our inbound packet will be processed by the capture hooks, even if no packet capture is running (this then must presumably be very cheap), before being passed to the correct protocol handler, in this case&amp;nbsp;&lt;code&gt;ip_rcv&lt;/code&gt;.&lt;br /&gt;
&lt;h2 id=&quot;the-socket-buffer&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;the-socket-buffer&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;the-socket-buffer&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
The socket buffer&lt;/h2&gt;
&lt;div style=&quot;border-top-color: rgb(238, 238, 238); border-top-style: solid; border-top-width: 1px; padding-top: 8px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://raw.githubusercontent.com/epickrram/blog-images/master/2016_05/SocketBufferAccess.jpg&quot; imageanchor=&quot;1&quot; style=&quot;color: #4d469c; margin-left: 1em; margin-right: 1em; text-decoration: none;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;340&quot; src=&quot;https://raw.githubusercontent.com/epickrram/blog-images/master/2016_05/SocketBufferAccess.jpg&quot; style=&quot;-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 0px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; border: 1px solid transparent; box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 0px; padding: 8px; position: relative;&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
As discussed previously, each socket on the system has a receive-side FIFO queue that is written to by the kernel, and read from by the user application.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/ip_input.c?v=4.0#L376&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;ip_rcv&lt;/a&gt;&lt;/code&gt;&amp;nbsp;starts by getting its own copy of the incoming packet, copying if the packet is already shared. If the copy fails due to lack of memory, then the packet is discarded, and the&amp;nbsp;&lt;code&gt;Discard&lt;/code&gt;&amp;nbsp;count of the global ip statistics table is incremented. Other checks made at this point include the IP checksum, header-length check and truncation check, each of which update the relevant metrics.&lt;br /&gt;
&lt;br /&gt;
Before calling the&amp;nbsp;&lt;code&gt;ip_rcv_finish&lt;/code&gt;&amp;nbsp;function, the packet is diverted through the&amp;nbsp;&lt;code&gt;netfilter&lt;/code&gt;&amp;nbsp;module where software-based network filtering can be applied.&lt;br /&gt;
&lt;br /&gt;
Assuming that the packet is not dropped by a filter,&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/ip_input.c?v=4.0#L312&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;ip_rcv_finish&lt;/code&gt;&lt;/a&gt;&amp;nbsp;passes the packet on to the next protocol-handler in the chain, in this instance,&amp;nbsp;&lt;code&gt;udp_rcv&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
In the internals of the&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1749&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;udp_rcv&lt;/code&gt;&lt;/a&gt;&amp;nbsp;function, we finally get to the point of accessing the socket FIFO queue.&lt;br /&gt;
Simple validation performed at this point includes packet-length check and checksum. Failure of these checks will cause the relevant statistics to be updated in the global udp statistics table.&lt;br /&gt;
&lt;br /&gt;
Because the traffic we&#39;re tracing&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1801&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;is multicast&lt;/a&gt;, the next handler function is&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1660&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;__udp4_lib_mcast_deliver&lt;/code&gt;&lt;/a&gt;.&lt;br /&gt;
With some exotic locking in place, the kernel determines how many different sockets this multicast packet needs to be delivered to. It is worth noting here that there is a smallish number (&lt;code&gt;256 / sizeof( struct sock)&lt;/code&gt;) of sockets that can be listening to a given multicast address before the possibility of greater lock-contention creeps in.&lt;br /&gt;
&lt;br /&gt;
An effort is made to enumerate the registered sockets with a lock held, then perform the packet dispatching without a lock. However, if the number of registered sockets exceeds the specified threshold, then packet dispatch (the&amp;nbsp;&lt;code&gt;flush_stack&lt;/code&gt;&amp;nbsp;function) will be handled while a lock is held.&lt;br /&gt;
&lt;br /&gt;
Once in&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1614&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;flush_stack&lt;/code&gt;&lt;/a&gt;, the packet is copied for each registered socket, and pushed onto the FIFO queue.&lt;br /&gt;
If the kernel is unable to allocate memory in order to copy the buffer, the socket&#39;s drop-count will be incremented, along with the&amp;nbsp;&lt;code&gt;RcvBufErrors&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code&gt;InErrors&lt;/code&gt;&amp;nbsp;metrics in the global udp statistics table.&lt;br /&gt;
&lt;br /&gt;
After another checksum test, we are finally at the point where socket-buffer overflow&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1584&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;is tested&lt;/a&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;if (sk_rcvqueues_full(sk, sk-&amp;gt;sk_rcvbuf)) {
    UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
                     is_udplite);
    goto drop;
}&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
If the size of the socket&#39;s backlog queue, plus the memory used in the receive queue is greater than the socket receive buffer size, then the&amp;nbsp;&lt;code&gt;RcvBufferErrors&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code&gt;InErrors&lt;/code&gt;&amp;nbsp;metrics are updated in the global udp statitics table, along with the socket&#39;s drop count.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1594&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;safely handle multi-threaded access to the socket buffer&lt;/a&gt;, if an application has locked the socket, then the inbound packet will be queued to the socket&#39;s&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/include/net/sock.h?v=4.0#L335&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;backlog queue&lt;/a&gt;. The backlog queue will be processed when the lock owner releases the lock.&lt;br /&gt;
&lt;br /&gt;
Otherwise, pending more checks that socket memory limits have not been exceeded, the packet is added to the socket&#39;s&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/sock.c?v=4.0#L439&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;sk_receive_queue&lt;/code&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Finally, once the packet has been delivered to the socket&#39;s receive queue, notification is&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/sock.c?v=4.0#L474&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;sent to any interested listeners&lt;/a&gt;.&lt;br /&gt;
&lt;h2 id=&quot;kernel-statistics&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;kernel-statistics&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;kernel-statistics&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
Kernel statistics&lt;/h2&gt;
&lt;div style=&quot;border-top-color: rgb(238, 238, 238); border-top-style: solid; border-top-width: 1px; padding-top: 8px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
Now that we have seen where the various capacity checks are made, we can make some observations in the&amp;nbsp;&lt;code&gt;proc&lt;/code&gt;&amp;nbsp;file system.&lt;br /&gt;
&lt;br /&gt;
There are protocol-specific files in&amp;nbsp;&lt;code&gt;/proc/net&lt;/code&gt;&amp;nbsp;that are updated by the kernel whenever data is received.&lt;br /&gt;
&lt;h3 id=&quot;procnetsnmp&quot; style=&quot;margin: 0px; position: relative;&quot;&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/h3&gt;
&lt;h3 id=&quot;procnetsnmp&quot; style=&quot;margin: 0px; position: relative;&quot;&gt;
&lt;code&gt;/proc/net/snmp&lt;/code&gt;&lt;/h3&gt;
&lt;br /&gt;
This file contains statistics on multiple protocols, and is the target for updates to the UDP receive buffer errors. So when we want to know about system-wide receive errors, this is the place to look. When this file is read, a&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/proc.c?v=4.0#L374&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;function call&lt;/a&gt;&amp;nbsp;iterates through the stored values and writes them to the supplied destination. Such is the magic of&amp;nbsp;&lt;a href=&quot;https://en.wikipedia.org/wiki/Procfs&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;procfs&lt;/code&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
In the output below, we can see that there have been several receive errors (&lt;code&gt;RcvbufErrors&lt;/code&gt;), and the number is matched by the&amp;nbsp;&lt;code&gt;InErrors&lt;/code&gt;&amp;nbsp;metric:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors
Udp: 281604018683 4      261929024 42204463516 261929024    0            0&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the columns maps to a constant specified&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/proc.c?v=4.0#L176&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;here&lt;/a&gt;, so to determine when these values are updated, we simply need to&amp;nbsp;&lt;a href=&quot;https://www.google.co.uk/search?q=UDP_MIB_RCVBUFERRORS&amp;amp;sitesearch=lxr.free-electrons.com/source&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;search for the constant name&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There is a subtle difference between&amp;nbsp;&lt;code&gt;InErrors&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code&gt;RcvbufErrors&lt;/code&gt;, but in our case when looking for socket buffer overflow, we only care about&amp;nbsp;&lt;code&gt;RcvbufErrors&lt;/code&gt;.&lt;br /&gt;
&lt;h3 id=&quot;procnetudp&quot; style=&quot;margin: 0px; position: relative;&quot;&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/h3&gt;
&lt;h3 id=&quot;procnetudp&quot; style=&quot;margin: 0px; position: relative;&quot;&gt;
&lt;code&gt;/proc/net/udp&lt;/code&gt;&lt;/h3&gt;
&lt;br /&gt;
This file contains socket-specific statistics, which only live for the lifetime of a socket. As we have seen from the code so far, each time the&amp;nbsp;&lt;code&gt;RcvbufErrors&lt;/code&gt;&amp;nbsp;metric has been incremented, so too has the corresponding&amp;nbsp;&lt;code&gt;sk_drops&lt;/code&gt;&amp;nbsp;value for the target socket.&lt;br /&gt;
&lt;br /&gt;
So if we need to differentiate between drop events on a per-socket basis, this file is what we need to observe. The contents below can be explained by looking at the&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c#L2517&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;handler function&lt;/a&gt;&amp;nbsp;for socket data:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;[pricem@metal ~]# cat /proc/net/udp
sl  local_address rem_address   st tx_queue rx_queue ... inode ref pointer drops
47: 00000000:B87A 00000000:0000 07 00000000:00000000 ...  239982339 2 ffff88052885c440 0     
95: 4104C1EF:38AA 00000000:0000 07 00000000:00000000 ...  239994712 2 ffff8808507ed800 0     
95: BC04C1EF:38AA 00000000:0000 07 00000000:00000000 ...  175113818 2 ffff881054a8b080 0     
95: BE04C1EF:38AA 00000000:0000 07 00000000:00000000 ...  175113817 2 ffff881054a8b440 0     
...&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
For observing back-pressure, we are interested in the drops column, and the rx_queue column, which is a snapshot of the amount of queued data at the time of reading. Local and remote addresses are hex-encoded&amp;nbsp;&lt;code&gt;ip:port&lt;/code&gt;&amp;nbsp;addresses.&lt;br /&gt;
&lt;br /&gt;
Monitoring this file can tell us if our application is falling behind the packet arrival rate (increase in&amp;nbsp;&lt;code&gt;rx_queue&lt;/code&gt;), or whether the kernel was unable to copy a packet into the socket buffer due to it already being full (increase in&amp;nbsp;&lt;code&gt;drops&lt;/code&gt;).&lt;br /&gt;
&lt;h2 id=&quot;tracepoints&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;tracepoints&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
Tracepoints&lt;/h2&gt;
&lt;br /&gt;
If we wish to capture more data about packets that are being dropped, there a three tracepoints that are of interest.&lt;br /&gt;
&lt;ol&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/sock.c?v=4.0#L447&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;sock:sock_rcvqueue_full&lt;/code&gt;&lt;/a&gt;: called when the amount of memory already allocated to the socket buffer is greater than or equal to the configured socket buffer size.&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/sock.c?v=4.0#L2084&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;sock:sock_exceed_buf_limit&lt;/code&gt;&lt;/a&gt;: called when the kernel is unable to allocate more memory for the socket buffer.&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/ipv4/udp.c?v=4.0#L1473&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;udp:udp_fail_queue_rcv_skb&lt;/code&gt;&lt;/a&gt;: called shortly after the&amp;nbsp;&lt;code&gt;sock_rcvqueue_full&lt;/code&gt;&amp;nbsp;event trace for the same reason.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
These events can be captured using Linux kernel tracing tools such as&amp;nbsp;&lt;a href=&quot;https://perf.wiki.kernel.org/index.php/Main_Page&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;perf&lt;/code&gt;&lt;/a&gt;&amp;nbsp;or&amp;nbsp;&lt;a href=&quot;https://www.kernel.org/doc/Documentation/trace/ftrace.txt&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;&lt;code&gt;ftrace&lt;/code&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h2 id=&quot;summary&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
&lt;/h2&gt;
&lt;h2 id=&quot;summary&quot; style=&quot;border-bottom-color: transparent; border-bottom-style: solid; border-bottom-width: 1px; font-size: 14px; font-stretch: normal; line-height: normal; margin: 0px -15px; padding: 0.6em 15px 0.5em; position: relative;&quot;&gt;
Summary&lt;/h2&gt;
&lt;br /&gt;
Let&#39;s just recap the points of interest for monitoring throughput issues in the network receive path.&lt;br /&gt;
&lt;ol&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;code&gt;/proc/net/softnet_stat&lt;/code&gt;: contains statistics updated by the ksoftirq daemon. Useful metrics are processed, timesqueeze and dropped (discussed in detail in the&amp;nbsp;&lt;a href=&quot;https://epickrram.blogspot.co.uk/2016/05/navigating-linux-kernel-network-stack.html&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;last post&lt;/a&gt;).&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;code&gt;/proc/net/snmp&lt;/code&gt;: contains system-wide statistics for IP, TCP, UDP. Useful metrics indicate memory exhaustion, buffer exhaustion, etc.&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;code&gt;/proc/net/udp&lt;/code&gt;: contains per-socket information. Useful for monitoring queue depths/drops for a particular socket.&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;code&gt;/proc/net/dev&lt;/code&gt;:&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/net/core/net-procfs.c?v=4.0#L101&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;contains statistics&lt;/a&gt;&amp;nbsp;provided by network devices present on the system. Some supplied statistics are driver-specific.&lt;/li&gt;
&lt;li style=&quot;margin: 0px 0px 0.25em; padding: 0px;&quot;&gt;&lt;code&gt;/sys/class/net/DEV_NAME/statistics&lt;/code&gt;: provides&amp;nbsp;&lt;a href=&quot;http://lxr.free-electrons.com/source/include/uapi/linux/if_link.h?v=4.0#L41&quot; style=&quot;color: #4d469c; text-decoration: none;&quot;&gt;more detailed statistics&lt;/a&gt;&amp;nbsp;from the network device driver.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/4161994599315000849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/03/linux-network-stack.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/4161994599315000849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/4161994599315000849'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/03/linux-network-stack.html' title='Linux network stack'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-2239437256964777397</id><published>2020-03-29T20:08:00.002-07:00</published><updated>2020-04-03T19:25:07.046-07:00</updated><title type='text'>min_free_kbytes</title><content type='html'>&lt;div class=&quot;wikitext titlehack&quot;&gt;
&lt;h2 style=&quot;margin-bottom: 0.1em; margin-top: 0.5em;&quot;&gt;
How the Linux kernel divides up your RAM&lt;/h2&gt;
&lt;div class=&quot;posttitle&quot; style=&quot;opacity: 0.6;&quot;&gt;
&lt;small&gt;June 15, 2012&lt;/small&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;a href=&quot;https://wiki.skytech.dk/mediawiki/index.php/Page_allocation_failure._order:0,_mode:0x20&quot;&gt;min_free_kbytes cause disk cache fails&lt;/a&gt;&lt;br /&gt;
&lt;div class=&quot;wikitext&quot;&gt;
&lt;br /&gt;
The Linux kernel doesn&#39;t consider all of your physical RAM to be one great big undifferentiated pool of memory. Instead, it divides it up into a number of different memory regions (at least for kernel purposes), which it calls &#39;zones&#39; (to simplify slightly). What memory regions there are depends on whether your machine is 32-bit or 64-bit and also how complicated it is.&lt;br /&gt;
The zones are:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;DMA&lt;/code&gt;&amp;nbsp;is the low 16 MBytes of memory. At this point it exists for historical reasons; once upon what is now a long time ago, there was hardware that could only do DMA into this area of physical memory.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DMA32&lt;/code&gt;&amp;nbsp;exists only in 64-bit Linux; it is the low 4 GBytes of memory, more or less. It exists because the transition to large memory 64-bit machines has created a class of hardware that can only do DMA to the low 4 GBytes of memory.(This is where people mutter about everything old being new again.)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Normal&lt;/code&gt;&amp;nbsp;is different on 32-bit and 64-bit machines. On 64-bit machines, it is all RAM from 4GB or so on upwards. On 32-bit machines it is all RAM from 16 MB to 896 MB for complex and somewhat historical reasons.Note that this implies that machines with a 64-bit kernel can have very small amounts of Normal memory unless they have significantly more than 4GB of RAM. For example, a 2 GB machine running a 64-bit kernel will have no Normal memory at all while a 4 GB machine will have only a tiny amount of it.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HighMem&lt;/code&gt;&amp;nbsp;exists only on 32-bit Linux; it is all RAM above 896 MB, including RAM above 4 GB on sufficiently large machines.&lt;/li&gt;
&lt;/ul&gt;
Normally allocations can come from a more restrictive zone than you asked for if that&#39;s where the free memory is. For example, if you ask for Normal memory on a 64-bit machine and there isn&#39;t any but there&#39;s lots of DMA32, you&#39;ll get DMA32. It&#39;s just that kernel prefers to preserve DMA32 for things that have asked for it specifically.&lt;br /&gt;
Now, this is a slight simplification; actually, zones and memory are attached to a &#39;node&#39;. Ordinary machines have only a single node, node 0, but sufficiently large servers can have multiple nodes (we have one with eight). Nodes are how Linux represents&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Non-Uniform_Memory_Access&quot;&gt;NUMA&lt;/a&gt;&amp;nbsp;architectures. To simplify, each CPU is also associated with a node and the kernel will try to allocate memory for a process running on a CPU from that node&#39;s RAM, because it is considered &#39;closest&#39; to that CPU.&lt;br /&gt;
I believe that the special zones (DMA, DMA32, and on 32-bit machines, Normal) will only be present on one node, generally node 0. All other nodes will generally have only Normal (on 64-bit kernels) or HighMem (on 32-bit kernels) memory.&lt;br /&gt;
You can see a bunch of information about your system&#39;s nodes, zones, and the state of their memory in&amp;nbsp;&lt;code&gt;/proc/pagetypeinfo&lt;/code&gt;,&amp;nbsp;&lt;code&gt;/proc/zoneinfo&lt;/code&gt;,&amp;nbsp;&lt;code&gt;/proc/&amp;lt;pid&amp;gt;/numa_maps&lt;/code&gt;, and&amp;nbsp;&lt;code&gt;/proc/buddyinfo&lt;/code&gt;, which deserves an explanation of its own.&lt;br /&gt;
The kernel&#39;s basic unit of allocatable memory is the 4 KByte page (many stats are reported by page count, instead of memory size in Kbytes). The kernel also keeps track of larger contiguous blocks of pages because sometimes kernel code wants, say, a contiguous 64 kbyte block of memory.&amp;nbsp;&lt;code&gt;/proc/buddyinfo&lt;/code&gt;&amp;nbsp;shows you how many such free chunks there are for each allocation &#39;order&#39;. The &#39;order&#39; is 2^order pages, ie order 0 is a single page, order 1 is 2 pages (8 KB), order 2 is 4 pages (16 Kb), and so on.&lt;br /&gt;
So when /proc/buddyinfo reports, for example:&lt;br /&gt;
&lt;blockquote&gt;
&lt;code&gt;Node 0, zone DMA32 7 20 2 4 6 4 3 4 6 5 369&lt;/code&gt;&lt;/blockquote&gt;
This means that in the DMA32 zone on this machine there are currently 7 free solo 4kb pages, 20 8kb two-page chunks, 2 16kb chunks, and so on, all the way up to 369 1024-page (4 Mbyte) chunks. Since the kernel will split larger chunks to get smaller ones if it needs to, the DMA32 zone on this machine is in pretty good shape despite seeming to not have many order 0 4kb pages available.&lt;br /&gt;
(This is also what&amp;nbsp;&lt;code&gt;/proc/pagetypeinfo&lt;/code&gt;&amp;nbsp;means by &#39;order&#39; in its output.)&lt;br /&gt;
In fact, having a disproportionate number of order 0 pages free is generally a danger sign since order 0 pages exist only when the kernel can&#39;t merge them together to form higher-order free chunks. Lots of order 0 pages thus mean lots of fragmentation, where the kernel can&#39;t even find two adjacent aligned pages to merge into an 8kb order 1 chunk.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://engineering.linkedin.com/performance/optimizing-linux-memory-management-low-latency-high-throughput-databases&quot;&gt;linux mem management&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://lkml.iu.edu/hypermail/linux/kernel/1904.0/03600.html&quot;&gt;NFS hang, sk_drops increasing, segs_in not, pfmemalloc suspected&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://lkml.org/lkml/2019/4/10/283&quot;&gt;Code change PR&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.linuxatemyram.com/play.html&quot;&gt;play with disk cache&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://renesasrulz.com/the_vault/f/archive-forum/14516/linux-kernel-out-of-memory-conditions-and-tuning-of-disk-cache-usage&quot;&gt;kernel run out men and disk cache&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://serverfault.com/questions/236170/page-allocation-failure-am-i-running-out-of-memory&quot;&gt;network stack continous mem&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://unix.stackexchange.com/questions/128539/what-would-happen-if-the-amount-of-free-memory-vm-min-free-kbytes-was-too-low&quot;&gt;low min_free_kbytes can cause cache reclaim failure&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://donghao.org/2016/03/25/avoid-page-allocation-failure-for-linux-kernel/&quot;&gt;Increase min_free_kbytes to 4GB&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://web.archive.org/web/20080419012851/http://people.redhat.com/dduval/kernel/min_free_kbytes.html&quot;&gt;memory zone&#39;s min/low/high graph &lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/2239437256964777397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2020/03/minfreekbytes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2239437256964777397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2239437256964777397'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2020/03/minfreekbytes.html' title='min_free_kbytes'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-665811286930977869</id><published>2019-12-16T07:36:00.002-08:00</published><updated>2019-12-25T15:41:55.116-08:00</updated><title type='text'></title><content type='html'>python links:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://pymotw.com/3/py-modindex.html#&quot;&gt;Python module index&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cito.github.io/blog/f-strings/&quot;&gt;formated string literals&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
c++ links:&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://www.linkedin.com/pulse/7-advanced-c-concepts-you-should-know-vishal-chovatiya/&quot;&gt;7 C++ idioms&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/lefticus/cppbestpractices&quot;&gt;cppbestpractices&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/665811286930977869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/12/python-links-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/665811286930977869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/665811286930977869'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/12/python-links-1.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-2573135688796476537</id><published>2019-10-26T20:36:00.000-07:00</published><updated>2019-11-06T10:02:11.777-08:00</updated><title type='text'></title><content type='html'>python jinja2 template&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://medium.com/@jasonrigden/jinja2-templating-engine-tutorial-4bd31fb4aea3&quot;&gt;Jinja2 tutorial&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/5121931/in-python-how-can-you-load-yaml-mappings-as-ordereddicts&quot;&gt;yaml load ordered_dict&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/2573135688796476537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/10/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2573135688796476537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2573135688796476537'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/10/blog-post.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-6914216046944831529</id><published>2019-09-17T03:55:00.003-07:00</published><updated>2019-09-17T03:55:35.501-07:00</updated><title type='text'>Smart pointers</title><content type='html'>&lt;a href=&quot;https://lokiastari.com/blog/2015/01/15/c-plus-plus-by-example-smart-pointer-part-ii/&quot;&gt;https://lokiastari.com/blog/2015/01/15/c-plus-plus-by-example-smart-pointer-part-ii/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/6914216046944831529/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/09/smart-pointers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/6914216046944831529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/6914216046944831529'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/09/smart-pointers.html' title='Smart pointers'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-819714318618080066</id><published>2019-09-17T03:52:00.001-07:00</published><updated>2019-09-24T21:28:10.941-07:00</updated><title type='text'></title><content type='html'>COPY and SWAP idiom&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom&quot;&gt;https://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.deleaker.com/blog/2018/11/20/copy-semantics-and-resource-management-in-cpp/#id-copy-on-write&quot;&gt;swap and move&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 17px; font-stretch: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
Why do we need the copy-and-swap idiom?&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Any class that manages a resource (a&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;wrapper&lt;/span&gt;, like a smart pointer) needs to implement&amp;nbsp;&lt;a href=&quot;https://stackoverflow.com/questions/4172722/what-is-the-rule-of-three&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The Big Three&lt;/a&gt;. While the goals and implementation of the copy-constructor and destructor are straightforward, the copy-assignment operator is arguably the most nuanced and difficult. How should it be done? What pitfalls need to be avoided?&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;copy-and-swap idiom&lt;/span&gt;&amp;nbsp;is the solution, and elegantly assists the assignment operator in achieving two things: avoiding&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Don%27t_repeat_yourself&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;code duplication&lt;/a&gt;, and providing a&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Exception_guarantees&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;strong exception guarantee&lt;/a&gt;.&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 17px; font-stretch: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
How does it work?&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom/3279616#3279616&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Conceptually&lt;/a&gt;, it works by using the copy-constructor&#39;s functionality to create a local copy of the data, then takes the copied data with a&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;function, swapping the old data with the new data. The temporary copy then destructs, taking the old data with it. We are left with a copy of the new data.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
In order to use the copy-and-swap idiom, we need three things: a working copy-constructor, a working destructor (both are the basis of any wrapper, so should be complete anyway), and a&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;function.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
A swap function is a&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;non-throwing&lt;/span&gt;&amp;nbsp;function that swaps two objects of a class, member for member. We might be tempted to use&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;std::swap&lt;/code&gt;&amp;nbsp;instead of providing our own, but this would be impossible;&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;std::swap&lt;/code&gt;&amp;nbsp;uses the copy-constructor and copy-assignment operator within its implementation, and we&#39;d ultimately be trying to define the assignment operator in terms of itself!&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
(Not only that, but unqualified calls to&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;will use our custom swap operator, skipping over the unnecessary construction and destruction of our class that&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;std::swap&lt;/code&gt;&amp;nbsp;would entail.)&lt;/div&gt;
&lt;hr style=&quot;background-color: #d6d9dc; border: 0px; box-sizing: inherit; color: #d6d9dc; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; height: 1px; margin-bottom: 20px;&quot; /&gt;
&lt;h2 style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 19px; font-stretch: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
An in-depth explanation&lt;/h2&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 17px; font-stretch: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
The goal&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Let&#39;s consider a concrete case. We want to manage, in an otherwise useless class, a dynamic array. We start with a working constructor, copy-constructor, and destructor:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
This class almost manages the array successfully, but it needs&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;operator=&lt;/code&gt;&amp;nbsp;to work correctly.&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 17px; font-stretch: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
A failed solution&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Here&#39;s how a naive implementation might look:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
And we say we&#39;re finished; this now manages an array, without leaks. However, it suffers from three problems, marked sequentially in the code as&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;(n)&lt;/code&gt;.&lt;/div&gt;
&lt;ol style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
The first is the self-assignment test. This check serves two purposes: it&#39;s an easy way to prevent us from running needless code on self-assignment, and it protects us from subtle bugs (such as deleting the array only to try and copy it). But in all other cases it merely serves to slow the program down, and act as noise in the code; self-assignment rarely occurs, so most of the time this check is a waste. It would be better if the operator could work properly without it.&lt;/div&gt;
&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
The second is that it only provides a basic exception guarantee. If&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;new int[mSize]&lt;/code&gt;&amp;nbsp;fails,&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;*this&lt;/code&gt;&amp;nbsp;will have been modified. (Namely, the size is wrong and the data is gone!) For a strong exception guarantee, it would need to be something akin to:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; margin-top: 0.5em; max-height: 600px; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
The code has expanded! Which leads us to the third problem: code duplication. Our assignment operator effectively duplicates all the code we&#39;ve already written elsewhere, and that&#39;s a terrible thing.&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
In our case, the core of it is only two lines (the allocation and the copy), but with more complex resources this code bloat can be quite a hassle. We should strive to never repeat ourselves.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
(One might wonder: if this much code is needed to manage one resource correctly, what if my class manages more than one? While this may seem to be a valid concern, and indeed it requires non-trivial&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;try&lt;/code&gt;/&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;catch&lt;/code&gt;&amp;nbsp;clauses, this is a non-issue. That&#39;s because a class should manage&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Single_responsibility_principle&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;one resource only&lt;/span&gt;&lt;/a&gt;!)&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 17px; font-stretch: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
A successful solution&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
As mentioned, the copy-and-swap idiom will fix all these issues. But right now, we have all the requirements except one: a&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;function. While The Rule of Three successfully entails the existence of our copy-constructor, assignment operator, and destructor, it should really be called &quot;The Big Three and A Half&quot;: any time your class manages a resource it also makes sense to provide a&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;function.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
We need to add swap functionality to our class, and we do that as follows†:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
(&lt;a href=&quot;https://stackoverflow.com/questions/5695548/public-friend-swap-member-function&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Here&lt;/a&gt;&amp;nbsp;is the explanation why&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;public friend swap&lt;/code&gt;.) Now not only can we swap our&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;dumb_array&lt;/code&gt;&#39;s, but swaps in general can be more efficient; it merely swaps pointers and sizes, rather than allocating and copying entire arrays. Aside from this bonus in functionality and efficiency, we are now ready to implement the copy-and-swap idiom.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Without further ado, our assignment operator is:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
And that&#39;s it! With one fell swoop, all three problems are elegantly tackled at once.&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 17px; font-stretch: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
Why does it work?&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
We first notice an important choice: the parameter argument is taken&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;by-value&lt;/span&gt;. While one could just as easily do the following (and indeed, many naive implementations of the idiom do):&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
We lose an&amp;nbsp;&lt;a href=&quot;https://web.archive.org/web/20140113221447/http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;important optimization opportunity&lt;/a&gt;. Not only that, but this choice is critical in C++11, which is discussed later. (On a general note, a remarkably useful guideline is as follows: if you&#39;re going to make a copy of something in a function, let the compiler do it in the parameter list.‡)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Either way, this method of obtaining our resource is the key to eliminating code duplication: we get to use the code from the copy-constructor to make the copy, and never need to repeat any bit of it. Now that the copy is made, we are ready to swap.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Observe that upon entering the function that all the new data is already allocated, copied, and ready to be used. This is what gives us a strong exception guarantee for free: we won&#39;t even enter the function if construction of the copy fails, and it&#39;s therefore not possible to alter the state of&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;*this&lt;/code&gt;. (What we did manually before for a strong exception guarantee, the compiler is doing for us now; how kind.)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
At this point we are home-free, because&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;is non-throwing. We swap our current data with the copied data, safely altering our state, and the old data gets put into the temporary. The old data is then released when the function returns. (Where upon the parameter&#39;s scope ends and its destructor is called.)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Because the idiom repeats no code, we cannot introduce bugs within the operator. Note that this means we are rid of the need for a self-assignment check, allowing a single uniform implementation of&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;operator=&lt;/code&gt;. (Additionally, we no longer have a performance penalty on non-self-assignments.)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
And that is the copy-and-swap idiom.&lt;/div&gt;
&lt;h2 style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 19px; font-stretch: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
What about C++11?&lt;/h2&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The next version of C++, C++11, makes one very important change to how we manage resources: the Rule of Three is now&amp;nbsp;&lt;strong style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The Rule of Four&lt;/strong&gt;&amp;nbsp;(and a half). Why? Because not only do we need to be able to copy-construct our resource,&amp;nbsp;&lt;a href=&quot;https://stackoverflow.com/questions/3106110/can-someone-please-explain-move-semantics-to-me&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;we need to move-construct it as well&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Luckily for us, this is easy:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
What&#39;s going on here? Recall the goal of move-construction: to take the resources from another instance of the class, leaving it in a state guaranteed to be assignable and destructible.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
So what we&#39;ve done is simple: initialize via the default constructor (a C++11 feature), then swap with&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;other&lt;/code&gt;; we know a default constructed instance of our class can safely be assigned and destructed, so we know&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;other&lt;/code&gt;&amp;nbsp;will be able to do the same, after swapping.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
(Note that some compilers do not support constructor delegation; in this case, we have to manually default construct the class. This is an unfortunate but luckily trivial task.)&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 17px; font-stretch: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
Why does that work?&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
That is the only change we need to make to our class, so why does it work? Remember the ever-important decision we made to make the parameter a value and not a reference:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Now, if&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;other&lt;/code&gt;&amp;nbsp;is being initialized with an rvalue,&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;it will be move-constructed&lt;/span&gt;. Perfect. In the same way C++03 let us re-use our copy-constructor functionality by taking the argument by-value, C++11 will&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;automatically&lt;/span&gt;&amp;nbsp;pick the move-constructor when appropriate as well. (And, of course, as mentioned in previously linked article, the copying/moving of the value may simply be elided altogether.)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
And so concludes the copy-and-swap idiom.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/819714318618080066/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/09/copy-and-swap-idiom-httpsstackoverflow.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/819714318618080066'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/819714318618080066'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/09/copy-and-swap-idiom-httpsstackoverflow.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-455471919543670959</id><published>2019-08-23T09:49:00.001-07:00</published><updated>2019-09-16T04:54:09.297-07:00</updated><title type='text'></title><content type='html'>Lock free programming:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://preshing.com/20120612/an-introduction-to-lock-free-programming/&quot;&gt;https://preshing.com/20120612/an-introduction-to-lock-free-programming/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
memory ordering:&lt;br /&gt;
&lt;a href=&quot;https://bartoszmilewski.com/2008/12/01/c-atomics-and-memory-ordering/&quot;&gt;https://bartoszmilewski.com/2008/12/01/c-atomics-and-memory-ordering/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Kernel tuning:&lt;br /&gt;
&lt;br /&gt;
cat /proc/cmdline&lt;br /&gt;
BOOT_IMAGE=/vmlinuz-3.10.0-123.el7.x86_64 root=UUID=d34860b6-1642-4a58-9a45-80e398065f28 ro vconsole.keymap=us crashkernel=auto vconsole.font=latarcyrheb-sun16 rhgb quiet console=ttyS1 intel_idle.max_cstate=0 processor.max_cstate=0 idle=poll hugepages=16384 isolcpus=1-8,10-35 nohz_full=1-8,10-35 rcu_nocbs=1-8,10-35 thermal.off=1 gbpages nosoftlockup&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://software.intel.com/en-us/articles/optimizing-computer-applications-for-latency-part-2-tuning-applications&quot;&gt;software tuning&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://leonmercanti.com/books/personal-development/Cracking%20the%20Coding%20Interview%20189%20Programming%20Questions%20and%20Solutions.pdf&quot;&gt;crack inter&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/455471919543670959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/08/lock-free-programming-httpspreshing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/455471919543670959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/455471919543670959'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/08/lock-free-programming-httpspreshing.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-7091280271467559681</id><published>2019-08-13T10:05:00.002-07:00</published><updated>2019-08-13T10:05:28.652-07:00</updated><title type='text'></title><content type='html'>dvt-nj01-sv104:messages $ wireshark -X lua_script:/home/enguang/work/git/tng/fdk/yaml/messages/vfm_dissector.lua&amp;amp;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/Open-Markets-Initiative/wireshark-lua&quot;&gt;https://github.com/Open-Markets-Initiative/wireshark-lua&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/7091280271467559681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/08/dvt-nj01-sv104messages-wireshark-x.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7091280271467559681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7091280271467559681'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/08/dvt-nj01-sv104messages-wireshark-x.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-4693631778488009218</id><published>2019-07-11T05:06:00.004-07:00</published><updated>2019-07-11T05:06:44.395-07:00</updated><title type='text'></title><content type='html'>&lt;h1 style=&quot;background-color: #fdfdfd; box-sizing: inherit; color: #50317b; font-family: &amp;quot;Titillium Web&amp;quot;, sans-serif; font-size: 3em; font-weight: 400; line-height: 1.2; margin: 0px 0px 0.75em;&quot;&gt;
Illustrated Guide to Monitoring and Tuning the Linux Networking Stack: Receiving Data:&lt;/h1&gt;
&lt;div&gt;
&lt;a href=&quot;https://blog.packagecloud.io/eng/2016/10/11/monitoring-tuning-linux-networking-stack-receiving-data-illustrated/&quot;&gt;Tuning receive buf&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/4693631778488009218/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/07/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/4693631778488009218'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/4693631778488009218'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/07/blog-post.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-3177995168111596265</id><published>2019-05-10T07:33:00.003-07:00</published><updated>2019-05-10T07:33:59.555-07:00</updated><title type='text'></title><content type='html'>&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/45538993/why-dont-memory-allocators-actively-return-freed-memory-to-the-os&quot;&gt;memory allocation&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
First, some clarification. You asked:&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;... my program a.out terminates already, there is no other process that is maintaining this memory cache - or, is there one?&lt;/em&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Everything we are talking about is within the lifetime of a single process: the process&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;always&lt;/em&gt;&amp;nbsp;returns all allocated memory when it exits. There is no cache that outlives the process&lt;sup style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 12px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1; margin: 0px; padding: 0px;&quot;&gt;1&lt;/sup&gt;. The memory is returned even without any help from the runtime allocator: the OS simply &quot;takes it back&quot; when the process is terminated. So there is no system-wide leak possible from terminated applications with normal allocations.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Now what Valgrind is reporting is memory that is in use&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;at the moment the process&lt;/em&gt;&amp;nbsp;terminated, but before the OS cleans everything up. It works at the&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;runtime library&lt;/em&gt;&amp;nbsp;level, and not at the OS level. So it&#39;s saying &quot;Hey, when the program finished, there were 72,000 bytes that hadn&#39;t been returned to the runtime&quot; but an unstated implication is that &quot;these allocations will be cleaned up shortly by the OS&quot;.&lt;/div&gt;
&lt;h1 style=&quot;background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 21px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: 1.3; margin: 0px 0px 1em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;
The Underlying Questions&lt;/h1&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The code and Valgrind output shown doesn&#39;t really correlate well with the titular question, so let&#39;s break them apart. First we&#39;ll just try to answer the questions you asked about allocators: why they exist and why they don&#39;t generally don&#39;t immediately return freed memory to the OS, ignoring the example.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
You asked:&lt;/div&gt;
&lt;blockquote style=&quot;background-color: cornsilk; border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: rgb(255, 235, 142); border-left-style: solid; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 0px 2px; box-sizing: inherit; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 10px; padding: 10px; quotes: none; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
1) Why keep them in an internal cache? If it is for speed, how is it faster? Yes, the OS needs to maintain a data structure to keep track of memory allocation, but this the maintainer of this cache also needs to do so.&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
This is sort of two questions in one: one is why bother having a userland runtime allocator at all, and then the other one is (perhaps?) why don&#39;t these allocators immediately return memory to the OS when it is freed. They are related, but let&#39;s tackle them one at a time.&lt;/div&gt;
&lt;h2 style=&quot;background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 19px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;
Why Runtime Allocators Exist&lt;/h2&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Why not just rely on the OS memory allocation routines?&lt;/div&gt;
&lt;ul style=&quot;background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Many operating systems, including most Linux and other Unix-like operating systems, simply don&#39;t have an OS system call to allocate and free arbitrary blocks of memory. Unix-alikes offer&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;brk&lt;/code&gt;&amp;nbsp;which only grows or shrinks one contiguous block of memory - you have no way to &quot;free&quot; arbitrary earlier allocations. They also offer&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;mmap&lt;/code&gt;&amp;nbsp;which allows you to independently allocate and free chunks of memory, but these allocate on a&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;PAGE_SIZE&lt;/code&gt;&amp;nbsp;granularity, which on Linux is 4096 bytes. So if you want request 32 bytes, you&#39;ll have to waste&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;4096 - 32 == 4064&lt;/code&gt;&amp;nbsp;bytes if you don&#39;t have your own allocator. On these operating systems you practically&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;need&lt;/em&gt;&amp;nbsp;a separate memory allocation runtime which turns these coarse-grained tools into something capable of efficiently allocating small blocks.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
Windows is a bit different. It has the&amp;nbsp;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/aa366597(v=vs.85).aspx&quot; rel=&quot;nofollow noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;HeapAlloc&lt;/code&gt;&lt;/a&gt;&amp;nbsp;call, which is part of the &quot;OS&quot; and does offer&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;malloc&lt;/code&gt;-like capabilities of allocating and freeing arbitrarily sized chunks of memory. With&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;some&lt;/em&gt;compilers then,&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;malloc&lt;/code&gt;&amp;nbsp;is just implemented as a thin wrapper around&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;HeapAlloc&lt;/code&gt;&amp;nbsp;(the performance of this call has improved greatly in recent Windows versions, making this feasible). Still, while&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;HeapAlloc&lt;/code&gt;&amp;nbsp;is part of the&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OS&lt;/em&gt;&amp;nbsp;it isn&#39;t implemented in the&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;kernel&lt;/em&gt;&amp;nbsp;- it is also mostly implemented in a user-mode library, managing a list of free and used blocks, with occasional kernel calls to get chunks of memory from the kernel. So it is mostly&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;malloc&lt;/code&gt;&amp;nbsp;in another disguise and any memory it is holding on to is also not available to any other processes.&lt;/div&gt;
&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;Performance! Even if there were appropriate kernel-level calls to allocate arbitrary blocks of memory, the simple overhead roundtrip to the kernel is usually hundreds of nanoseconds or more. A well-tuned&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;malloc&lt;/code&gt;&amp;nbsp;allocation or free, on other hand, is often only a dozen instructions and may complete in 10 ns or less. On top of that, system calls can&#39;t &quot;trust their input&quot; and so must carefully validate parameters passed from user-space. In the case of&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;free&lt;/code&gt;&amp;nbsp;this means that it much check that the user passed a pointer which is valid! Most runtime&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;free&lt;/code&gt;&amp;nbsp;implements simply crash or silently corrupt memory since there is no responsibility to protect a process from itself.&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;Closer link to the rest of the language runtime. The functions you use to allocate memory in C++, namely&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;new&lt;/code&gt;,&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;malloc&lt;/code&gt;&amp;nbsp;and friends, are part of an defined by the language. It is then entirely natural to implement them as part of the runtime that implements the rest of the language, rather than the OS which is for the most part language-agnostic. For example, the language may have specific alignment requirements for various objects, which can best be handled by language aware allocators. Changes to the language or compiler might also imply necessary changes to the allocation routines, and it would be a tough call to hope for the kernel to be updated to accommodate your language features!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style=&quot;background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 19px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;
Why Not Return Memory to the OS&lt;/h2&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Your example doesn&#39;t show it, but you asked and if you wrote a different test you would probably find that after allocating and then freeing a bunch of memory, your processes resident set size and/or virtual size as reported by the OS might not decrease after the free. That is, it seems like the process holds on to the memory even though you have freed it. This is in fact true of many&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;malloc&lt;/code&gt;implementations. First, note that this is not a&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;leak&lt;/em&gt;&amp;nbsp;per se - the unreturned memory is still available to the process that allocated it, even if not to other processes.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Why do they do that? Here are some reasons:&lt;/div&gt;
&lt;ol style=&quot;background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The kernel API makes it hard. For the old-school&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;brk&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;sbrk&lt;/code&gt;&amp;nbsp;&lt;a href=&quot;https://linux.die.net/man/2/sbrk&quot; rel=&quot;nofollow noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;system calls&lt;/a&gt;, it simply isn&#39;t feasible to return freed memory unless it happens to be at the end of very last block allocated from&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;brk&lt;/code&gt;&amp;nbsp;or&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;sbrk&lt;/code&gt;. That&#39;s because the abstraction offered by these calls is a single large contiguous region that you can only extend from one end. You can&#39;t hand back memory from the middle of it. Rather than trying to support the unusual case where all the freed memory happens to be at the end of&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;brk&lt;/code&gt;&amp;nbsp;region, most allocators don&#39;t even bother.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;mmap&lt;/code&gt;&amp;nbsp;call is more flexible (and this discussion generally applies also to Windows where&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;VirtualAlloc&lt;/code&gt;&amp;nbsp;is the&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;mmap&lt;/code&gt;&amp;nbsp;equivalent), allowing you to at least return memory at a page granularity - but even that is hard! You can&#39;t return a page until&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;all&lt;/em&gt;&amp;nbsp;allocations that are part of that page are freed. Depending on the size and allocation/free pattern of the application that may be common or uncommon. A case where it works well is for large allocations - greater than a page. Here you&#39;re guaranteed to be able to free most of the allocation if it was done via&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;mmap&lt;/code&gt;&amp;nbsp;and indeed some modern allocators satisfy large allocations directly from&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;mmap&lt;/code&gt;&amp;nbsp;and free them back to the OS with&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;munmap&lt;/code&gt;. For&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;glibc&lt;/code&gt;&amp;nbsp;(and by extension the C++ allocation operators), you can even control&amp;nbsp;&lt;a href=&quot;http://man7.org/linux/man-pages/man3/mallopt.3.html&quot; rel=&quot;nofollow noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this threshold&lt;/a&gt;:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; margin-top: 0.5em; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;M_MMAP_THRESHOLD
  &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; allocations greater than or equal to the limit specified
  &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;in bytes&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; by M_MMAP_THRESHOLD that can&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;t be satisfied from
  the free &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; the memory&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;allocation functions employ mmap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
  instead of increasing the program &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; sbrk&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

  &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Allocating&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; memory &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mmap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; has the significant advantage
  that the allocated memory blocks can always be independently
  released back to the system&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;By&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; contrast&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; the heap can be
  trimmed only &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; memory is freed at the top end&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; the other
  hand&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; there are some disadvantages to the use of mmap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;):&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
  deallocated space is not placed on the free &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; reuse by
  later allocations&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; memory may be wasted because mmap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
  allocations must be page&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;aligned&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; and the kernel must perform
  the expensive task of zeroing out memory allocated via
  mmap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Balancing&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; these factors leads to a &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; setting
  of &lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;1024&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; the M_MMAP_THRESHOLD parameter&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
So by default allocations of 128K or more will be allocated by the runtime directly from the OS and freed back to the OS on free. So&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sometimes&lt;/em&gt;&amp;nbsp;you will see the behavior you might have expected is always the case.&lt;/div&gt;
&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;Performance! Every kernel call is expensive, as described in the other list above. Memory that is freed by a process will be needed shortly later to satisfy another allocation. Rather than trying to return it to the OS, a relatively heavyweight operation, why not just keep it around on a&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;free list&lt;/em&gt;to satisfy future allocations? As pointed out in the man page entry, this also avoids the overhead of zeroing out all the memory returned by the kernel. It also gives the best chance of good cache behavior since the process is continually re-using the same region of the address space. Finally, it avoids TLB flushes which would be imposed by&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;munmap&lt;/code&gt;&amp;nbsp;(and possibly by shrinking via&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;brk&lt;/code&gt;).&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 0.5em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;The &quot;problem&quot; of not returning memory is the worst for long-lived processes that allocate a bunch of memory at some point, free it and then never allocate that much again. I.e., processes whose allocation&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;high-water mark&lt;/em&gt;&amp;nbsp;is larger than their long term typical allocation amount. Most processes just don&#39;t follow that pattern, however. Processes often free a lot of memory, but allocate at a rate such that their overall memory use is constant or perhaps increasing. Applications that do have the &quot;big then small&quot; live size pattern could perhaps&amp;nbsp;&lt;a href=&quot;https://stackoverflow.com/questions/38644578/understanding-glibc-malloc-trimming&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;force the issue with&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;malloc_trim&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Virtual memory helps mitigate the issue. So far I&#39;ve been throwing around terms like &quot;allocated&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;memory&lt;/em&gt;&quot; without really defining what it means. If a program allocates and then frees 2 GB of&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;memory&lt;/em&gt;&amp;nbsp;and then sits around doing nothing, is it wasting 2 GB of actual DRAM plugged into your motherboard somewhere? Probably not. It is using 2 GB of virtual address space in your process, sure, but virtual address space is per-process, so that doesn&#39;t directly take anything away from other processes. If the process actually wrote to the memory at some point, it would be allocated physical memory (yes, DRAM) - after freeing it, you are - by definition - no longer using it. At this point the OS may reclaim those physical pages by use for someone else.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
Now this still requires you have swap to absorb the dirty not-used pages, but some allocators are smart: they can issue a&amp;nbsp;&lt;a href=&quot;http://man7.org/linux/man-pages/man2/madvise.2.html&quot; rel=&quot;nofollow noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;madvise(..., MADV_DONTNEED)&lt;/code&gt;&lt;/a&gt;&amp;nbsp;call which tells the OS &quot;this range doesn&#39;t have anything useful, you don&#39;t have to preserve its contents in swap&quot;. It still leaves the virtual address space mapped in the process and usable later (zero filled) and so it&#39;s more efficient than&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;munmap&lt;/code&gt;&amp;nbsp;and a subsequent&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;mmap&lt;/code&gt;, but it avoid pointlessly swapping freed memory regions to swap.&lt;sup style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 12px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1; margin: 0px; padding: 0px;&quot;&gt;2&lt;/sup&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 style=&quot;background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 21px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: 1.3; margin: 0px 0px 1em; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;&quot;&gt;
The Demonstrated Code&lt;/h1&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
As pointed out in&amp;nbsp;&lt;a href=&quot;https://stackoverflow.com/a/45537999/149138&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this answer&lt;/a&gt;&amp;nbsp;your test with&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;vector&amp;lt;int&amp;gt;&lt;/code&gt;&amp;nbsp;isn&#39;t really testing&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;anything&lt;/em&gt;&amp;nbsp;because an empty, unused&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;std::vector&amp;lt;int&amp;gt; v&lt;/code&gt;&amp;nbsp;won&#39;t even&amp;nbsp;&lt;a href=&quot;https://godbolt.org/g/XQc2Qy&quot; rel=&quot;nofollow noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;create the vector object&lt;/a&gt;&amp;nbsp;as long as you are using some minimal level of optimization. Even without optimization, no allocation is likely to occur because most&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;vector&lt;/code&gt;&amp;nbsp;implementations allocate on first insertion, and not in the constructor. Finally, even if you are using some unusual compiler or library that does an allocation, it will be for a handful of bytes, not the ~72,000 bytes Valgrind is reporting.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
You should do something like this to actually see the impact of a vector allocation:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border-radius: 3px; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;#include&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;lt;vector&amp;gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;volatile&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sink&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; main&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    std&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; v&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;12345678&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    sink &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
That results in&amp;nbsp;&lt;a href=&quot;https://godbolt.org/g/Givw4D&quot; rel=&quot;nofollow noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;actual allocation and de-allocation&lt;/a&gt;. It isn&#39;t going to change the Valgrind output, however, since the vector allocation is correctly freed before the program exits, so there is no issue as far as Valgrind is concerned.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
At a high level, Valgrind basically categorizes things into &quot;definite leaks&quot; and &quot;not freed at exit&quot;. The former occur when the program no longer has a reference to a pointer to memory that it allocated. It cannot free such memory and so has leaked it. Memory which hasn&#39;t been freed at exit may be a &quot;leak&quot; - i.e., objects that should have been freed, but it may also simply be memory that the developer knew would live the length of the program and so doesn&#39;t need to be explicitly freed (because of order-of-destruction issues for globals, especially when shared libraries are involved, it may be very hard to reliably free memory associated with global or static objects even if you wanted to).&lt;/div&gt;
&lt;hr style=&quot;background-color: #d6d9dc; border: 0px; box-sizing: inherit; color: #d6d9dc; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; height: 1px; margin-bottom: 20px;&quot; /&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;sup style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 12px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1; margin: 0px; padding: 0px;&quot;&gt;1&lt;/sup&gt;&amp;nbsp;In some cases some deliberately&amp;nbsp;&lt;em style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;special&lt;/em&gt;&amp;nbsp;allocations may outlive the process, such as shared memory and memory mapped files, but that doesn&#39;t relate to plain C++ allocations and you can ignore it for the purposes of this discussion.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;sup style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 12px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1; margin: 0px; padding: 0px;&quot;&gt;2&lt;/sup&gt;&amp;nbsp;Recent Linux kernels also have the Linux-specific&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;MADV_FREE&lt;/code&gt;&amp;nbsp;which seems to have similar semantics to&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;MADV_DONTNEED&lt;/code&gt;.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/3177995168111596265/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/05/memory-allocation-first-some.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/3177995168111596265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/3177995168111596265'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/05/memory-allocation-first-some.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-4016923598857745510</id><published>2019-05-04T12:15:00.002-07:00</published><updated>2019-05-04T12:45:48.029-07:00</updated><title type='text'></title><content type='html'>&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://blog.feabhas.com/2019/03/thanks-for-the-memory-allocator/#more-3035&quot;&gt;c++ memory allocator&lt;/a&gt;:&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://blog.feabhas.com/2018/12/a-brief-introduction-to-concepts-part-1/&quot;&gt;c++ concepts&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/4016923598857745510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/05/httpsblog.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/4016923598857745510'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/4016923598857745510'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/05/httpsblog.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-4850477189609526908</id><published>2019-01-18T06:51:00.001-08:00</published><updated>2019-01-20T10:16:55.690-08:00</updated><title type='text'></title><content type='html'>https://clang.llvm.org/extra/modularize.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
swap idiom&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;post-text&quot; itemprop=&quot;text&quot; style=&quot;border: 0px; box-sizing: inherit; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: 1.3; margin: 0px 0px 5px; padding: 0px; vertical-align: baseline; width: 665.28125px; word-wrap: break-word;&quot;&gt;
&lt;h2 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 19px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
Overview&lt;/h2&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 17px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
Why do we need the copy-and-swap idiom?&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Any class that manages a resource (a&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;wrapper&lt;/span&gt;, like a smart pointer) needs to implement&amp;nbsp;&lt;a href=&quot;https://stackoverflow.com/questions/4172722/what-is-the-rule-of-three&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The Big Three&lt;/a&gt;. While the goals and implementation of the copy-constructor and destructor are straightforward, the copy-assignment operator is arguably the most nuanced and difficult. How should it be done? What pitfalls need to be avoided?&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;copy-and-swap idiom&lt;/span&gt;&amp;nbsp;is the solution, and elegantly assists the assignment operator in achieving two things: avoiding&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Don%27t_repeat_yourself&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;code duplication&lt;/a&gt;, and providing a&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Exception_guarantees&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;strong exception guarantee&lt;/a&gt;.&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 17px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
How does it work?&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom/3279616#3279616&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Conceptually&lt;/a&gt;, it works by using the copy-constructor&#39;s functionality to create a local copy of the data, then takes the copied data with a&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;function, swapping the old data with the new data. The temporary copy then destructs, taking the old data with it. We are left with a copy of the new data.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
In order to use the copy-and-swap idiom, we need three things: a working copy-constructor, a working destructor (both are the basis of any wrapper, so should be complete anyway), and a&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;function.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
A swap function is a&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;non-throwing&lt;/span&gt;&amp;nbsp;function that swaps two objects of a class, member for member. We might be tempted to use&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;std::swap&lt;/code&gt;&amp;nbsp;instead of providing our own, but this would be impossible;&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;std::swap&lt;/code&gt;&amp;nbsp;uses the copy-constructor and copy-assignment operator within its implementation, and we&#39;d ultimately be trying to define the assignment operator in terms of itself!&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
(Not only that, but unqualified calls to&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;will use our custom swap operator, skipping over the unnecessary construction and destruction of our class that&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;std::swap&lt;/code&gt;&amp;nbsp;would entail.)&lt;/div&gt;
&lt;hr style=&quot;background-color: #d6d9dc; border: 0px; box-sizing: inherit; color: #d6d9dc; height: 1px; margin-bottom: 20px;&quot; /&gt;
&lt;h2 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 19px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
An in-depth explanation&lt;/h2&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 17px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
The goal&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Let&#39;s consider a concrete case. We want to manage, in an otherwise useless class, a dynamic array. We start with a working constructor, copy-constructor, and destructor:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;#include&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;lt;algorithm&amp;gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// std::copy&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;#include&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;lt;cstddef&amp;gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// std::size_t&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; dumb_array
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (default) constructor&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;size_t&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; size &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
          mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]()&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// copy-constructor&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
          mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// note that this is non-throwing, because of the data&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// types being used; more attention to detail with regards&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// to exceptions must be given in a more general case, however&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        std&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mArray &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// destructor&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;private&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    std&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;size_t&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
This class almost manages the array successfully, but it needs&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;operator=&lt;/code&gt;&amp;nbsp;to work correctly.&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 17px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
A failed solution&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Here&#39;s how a naive implementation might look:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// the hard part&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;operator&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=(&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (1)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get rid of the old data...&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (2)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        mArray &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (2) *(see footnote for rationale)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// ...and put in the new&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        mSize &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (3)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        mArray &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mSize &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (3)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        std&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mArray &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (3)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
And we say we&#39;re finished; this now manages an array, without leaks. However, it suffers from three problems, marked sequentially in the code as&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;(n)&lt;/code&gt;.&lt;/div&gt;
&lt;ol style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
The first is the self-assignment test. This check serves two purposes: it&#39;s an easy way to prevent us from running needless code on self-assignment, and it protects us from subtle bugs (such as deleting the array only to try and copy it). But in all other cases it merely serves to slow the program down, and act as noise in the code; self-assignment rarely occurs, so most of the time this check is a waste. It would be better if the operator could work properly without it.&lt;/div&gt;
&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
The second is that it only provides a basic exception guarantee. If&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;new int[mSize]&lt;/code&gt;&amp;nbsp;fails,&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;*this&lt;/code&gt;&amp;nbsp;will have been modified. (Namely, the size is wrong and the data is gone!) For a strong exception guarantee, it would need to be something akin to:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; margin-top: 0.5em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;operator&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=(&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (1)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get the new data ready before we replace the old&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        std&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;size_t&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; newSize &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; newArray &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; newSize &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;newSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]()&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (3)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        std&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mArray &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; newSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; newArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (3)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// replace the old data (all are non-throwing)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        mSize &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; newSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        mArray &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; newArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
The code has expanded! Which leads us to the third problem: code duplication. Our assignment operator effectively duplicates all the code we&#39;ve already written elsewhere, and that&#39;s a terrible thing.&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
In our case, the core of it is only two lines (the allocation and the copy), but with more complex resources this code bloat can be quite a hassle. We should strive to never repeat ourselves.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
(One might wonder: if this much code is needed to manage one resource correctly, what if my class manages more than one? While this may seem to be a valid concern, and indeed it requires non-trivial&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;try&lt;/code&gt;/&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;catch&lt;/code&gt;&amp;nbsp;clauses, this is a non-issue. That&#39;s because a class should manage&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Single_responsibility_principle&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;one resource only&lt;/span&gt;&lt;/a&gt;!)&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 17px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
A successful solution&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
As mentioned, the copy-and-swap idiom will fix all these issues. But right now, we have all the requirements except one: a&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;function. While The Rule of Three successfully entails the existence of our copy-constructor, assignment operator, and destructor, it should really be called &quot;The Big Three and A Half&quot;: any time your class manages a resource it also makes sense to provide a&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;function.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
We need to add swap functionality to our class, and we do that as follows†:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; dumb_array
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// ...&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;friend&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; swap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; first&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; second&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// nothrow&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// enable ADL (not necessary in our case, but good practice)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; std&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;swap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// by swapping the members of two objects,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// the two objects are effectively swapped&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        swap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; second&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mSize&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        swap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; second&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;mArray&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// ...&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
(&lt;a href=&quot;https://stackoverflow.com/questions/5695548/public-friend-swap-member-function&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Here&lt;/a&gt;&amp;nbsp;is the explanation why&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;public friend swap&lt;/code&gt;.) Now not only can we swap our&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;dumb_array&lt;/code&gt;&#39;s, but swaps in general can be more efficient; it merely swaps pointers and sizes, rather than allocating and copying entire arrays. Aside from this bonus in functionality and efficiency, we are now ready to implement the copy-and-swap idiom.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Without further ado, our assignment operator is:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;operator&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;dumb_array other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (1)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    swap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(*&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (2)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
And that&#39;s it! With one fell swoop, all three problems are elegantly tackled at once.&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 17px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
Why does it work?&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
We first notice an important choice: the parameter argument is taken&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;by-value&lt;/span&gt;. While one could just as easily do the following (and indeed, many naive implementations of the idiom do):&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;operator&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=(&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    dumb_array temp&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    swap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(*&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; temp&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
We lose an&amp;nbsp;&lt;a href=&quot;https://web.archive.org/web/20140113221447/http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;important optimization opportunity&lt;/a&gt;. Not only that, but this choice is critical in C++11, which is discussed later. (On a general note, a remarkably useful guideline is as follows: if you&#39;re going to make a copy of something in a function, let the compiler do it in the parameter list.‡)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Either way, this method of obtaining our resource is the key to eliminating code duplication: we get to use the code from the copy-constructor to make the copy, and never need to repeat any bit of it. Now that the copy is made, we are ready to swap.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Observe that upon entering the function that all the new data is already allocated, copied, and ready to be used. This is what gives us a strong exception guarantee for free: we won&#39;t even enter the function if construction of the copy fails, and it&#39;s therefore not possible to alter the state of&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;*this&lt;/code&gt;. (What we did manually before for a strong exception guarantee, the compiler is doing for us now; how kind.)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
At this point we are home-free, because&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;is non-throwing. We swap our current data with the copied data, safely altering our state, and the old data gets put into the temporary. The old data is then released when the function returns. (Where upon the parameter&#39;s scope ends and its destructor is called.)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Because the idiom repeats no code, we cannot introduce bugs within the operator. Note that this means we are rid of the need for a self-assignment check, allowing a single uniform implementation of&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;operator=&lt;/code&gt;. (Additionally, we no longer have a performance penalty on non-self-assignments.)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
And that is the copy-and-swap idiom.&lt;/div&gt;
&lt;h2 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 19px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
What about C++11?&lt;/h2&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The next version of C++, C++11, makes one very important change to how we manage resources: the Rule of Three is now&amp;nbsp;&lt;strong style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The Rule of Four&lt;/strong&gt;&amp;nbsp;(and a half). Why? Because not only do we need to be able to copy-construct our resource,&amp;nbsp;&lt;a href=&quot;https://stackoverflow.com/questions/3106110/can-someone-please-explain-move-semantics-to-me&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;we need to move-construct it as well&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Luckily for us, this is easy:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; dumb_array
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// ...&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// move constructor&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// initialize via default constructor, C++11 only&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
        swap&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(*&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// ...&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
What&#39;s going on here? Recall the goal of move-construction: to take the resources from another instance of the class, leaving it in a state guaranteed to be assignable and destructible.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
So what we&#39;ve done is simple: initialize via the default constructor (a C++11 feature), then swap with&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;other&lt;/code&gt;; we know a default constructed instance of our class can safely be assigned and destructed, so we know&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;other&lt;/code&gt;&amp;nbsp;will be able to do the same, after swapping.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
(Note that some compilers do not support constructor delegation; in this case, we have to manually default construct the class. This is an unfortunate but luckily trivial task.)&lt;/div&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 17px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
Why does that work?&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
That is the only change we need to make to our class, so why does it work? Remember the ever-important decision we made to make the parameter a value and not a reference:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;dumb_array&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;operator&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=(&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;dumb_array other&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (1)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Now, if&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;other&lt;/code&gt;&amp;nbsp;is being initialized with an rvalue,&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;it will be move-constructed&lt;/span&gt;. Perfect. In the same way C++03 let us re-use our copy-constructor functionality by taking the argument by-value, C++11 will&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;automatically&lt;/span&gt;&amp;nbsp;pick the move-constructor when appropriate as well. (And, of course, as mentioned in previously linked article, the copying/moving of the value may simply be elided altogether.)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
And so concludes the copy-and-swap idiom.&lt;/div&gt;
&lt;hr style=&quot;background-color: #d6d9dc; border: 0px; box-sizing: inherit; color: #d6d9dc; height: 1px; margin-bottom: 20px;&quot; /&gt;
&lt;h3 style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 17px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: 400; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
Footnotes&lt;/h3&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
*Why do we set&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;mArray&lt;/code&gt;&amp;nbsp;to null? Because if any further code in the operator throws, the destructor of&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;dumb_array&lt;/code&gt;&amp;nbsp;might be called; and if that happens without setting it to null, we attempt to delete memory that&#39;s already been deleted! We avoid this by setting it to null, as deleting null is a no-operation.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
†There are other claims that we should specialize&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;std::swap&lt;/code&gt;&amp;nbsp;for our type, provide an in-class&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;&amp;nbsp;along-side a free-function&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;, etc. But this is all unnecessary: any proper use of&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;swap&lt;/code&gt;will be through an unqualified call, and our function will be found through&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Argument-dependent_name_lookup&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;ADL&lt;/a&gt;. One function will do.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
‡The reason is simple: once you have the resource to yourself, you may swap and/or move it (C++11) anywhere it needs to be. And by making the copy in the parameter list, you maximize optimization.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;grid mb0 fw-wrap ai-start jc-end gs8 gsy&quot; style=&quot;align-items: flex-start !important; border: 0px; box-sizing: inherit; display: flex; flex-wrap: wrap !important; font-family: inherit; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; justify-content: flex-end !important; line-height: inherit; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px; margin-top: -4px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;time datetime=&quot;2010-07-19T08:43:14&quot; itemprop=&quot;dateCreated&quot; style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-stretch: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/time&gt;&lt;div class=&quot;grid--cell mr16&quot; style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; flex: 1 1 100px; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-stretch: inherit; line-height: inherit; margin: 4px 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/4850477189609526908/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2019/01/httpsclang.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/4850477189609526908'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/4850477189609526908'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2019/01/httpsclang.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-5700481190002940458</id><published>2018-12-16T14:43:00.002-08:00</published><updated>2018-12-16T14:43:33.603-08:00</updated><title type='text'>std::void_t</title><content type='html'>&lt;a href=&quot;https://stackoverflow.com/questions/27687389/how-does-void-t-work&quot;&gt;void_t&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
I watched Walter Brown&#39;s talk at Cppcon14 about modern template programming (&lt;a href=&quot;http://youtu.be/Am2is2QCvxY&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Part I&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;http://youtu.be/a0FliKwcwXE&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Part II&lt;/a&gt;) where he presented his&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void_t&lt;/code&gt;&amp;nbsp;SFINAE technique.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Example:&lt;br style=&quot;box-sizing: inherit;&quot; /&gt;Given a simple variable template that evaluates to&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void&lt;/code&gt;&amp;nbsp;if all template arguments are well formed:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
and the following trait that checks for the existence of a member variable called&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;member&lt;/span&gt;:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
I tried to understand why and how this works. Therefore a tiny example:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;1.&lt;/strong&gt;&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt; A &amp;gt;&lt;/code&gt;&lt;/div&gt;
&lt;ul style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt; A , void_t&amp;lt; decltype( A::member ) &amp;gt; &amp;gt;&lt;/code&gt;&lt;ul style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; list-style: disc; margin: 0px 0px 0px 30px; padding: 0.5em 0px 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;A::member&lt;/code&gt;&amp;nbsp;exists&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;decltype( A::member )&lt;/code&gt;&amp;nbsp;is well-formed&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void_t&amp;lt;&amp;gt;&lt;/code&gt;&amp;nbsp;is valid and evaluates to&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt; A , void &amp;gt;&lt;/code&gt;&amp;nbsp;and therefore it chooses the specialized template&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt; T , void &amp;gt;&lt;/code&gt;&amp;nbsp;and evaluates to&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;true_type&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;2.&lt;/strong&gt;&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt; B &amp;gt;&lt;/code&gt;&lt;/div&gt;
&lt;ul style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt; B , void_t&amp;lt; decltype( B::member ) &amp;gt; &amp;gt;&lt;/code&gt;&lt;ul style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; list-style: disc; margin: 0px 0px 0px 30px; padding: 0.5em 0px 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;B::member&lt;/code&gt;&amp;nbsp;does not exist&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;decltype( B::member )&lt;/code&gt;&amp;nbsp;is ill-formed and fails silently (sfinae)&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt; B , expression-sfinae &amp;gt;&lt;/code&gt;&amp;nbsp;so this template is discarded&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;compiler finds&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt; B , class = void &amp;gt;&lt;/code&gt;&amp;nbsp;with void as default argument&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt; B &amp;gt;&lt;/code&gt;&amp;nbsp;evaluates to&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;false_type&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;a href=&quot;http://ideone.com/HCTlBb&quot; rel=&quot;noreferrer&quot; style=&quot;border: 0px; box-sizing: inherit; color: #005999; cursor: pointer; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;http://ideone.com/HCTlBb&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Questions:&lt;br style=&quot;box-sizing: inherit;&quot; /&gt;1. Is my understanding of this correct?&lt;br style=&quot;box-sizing: inherit;&quot; /&gt;2. Walter Brown states that the default argument has to be the exact same type as the one used in&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void_t&lt;/code&gt;&amp;nbsp;for it to work. Why is that? (I don&#39;t see why this types need to match, doesn&#39;t just any default type does the job?)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
When you write&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt;A&amp;gt;::value&lt;/code&gt;, the compiler looks up the name&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&lt;/code&gt;&amp;nbsp;and finds the&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;primary&lt;/span&gt;&amp;nbsp;class template, that is, this declaration:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
(In the OP, that&#39;s written as a definition.)&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The template argument list&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&amp;lt;A&amp;gt;&lt;/code&gt;&amp;nbsp;is compared to the template parameter list of this primary template. Since the primary template has two parameters, but you only supplied one, the remaining parameter is defaulted to the default template argument:&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void&lt;/code&gt;. It&#39;s as if you had written&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt;A, void&amp;gt;::value&lt;/code&gt;.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Now, the template parameter list is compared against any specializations of the template&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&lt;/code&gt;. Only if no specialization matches, the definition of the primary template is used as a fall-back. So the partial specialization is taken into account:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The compiler tries to match the template arguments&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;A, void&lt;/code&gt;&amp;nbsp;with the patterns defined in the partial specialization:&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void_t&amp;lt;..&amp;gt;&lt;/code&gt;&amp;nbsp;one by one. First, template argument deduction is performed. The partial specialization above is still a template with template-parameters that need to be &quot;filled&quot; by arguments.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The first pattern,&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;, allows the compiler to deduce the template-parameter&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;. This is a trivial deduction, but consider a pattern like&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T const&amp;amp;&lt;/code&gt;, where we could still deduce&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;. For the pattern&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;and the template argument&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;A&lt;/code&gt;, we deduce&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;&amp;nbsp;to be&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;A&lt;/code&gt;.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); clear: both; color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
In the second pattern&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void_t&amp;lt; decltype( T::member ) &amp;gt;&lt;/code&gt;, the template-parameter&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;&amp;nbsp;appears in a context where it cannot be deduced from any template argument. There are two reasons for this:&lt;/div&gt;
&lt;ul style=&quot;border: 0px; box-sizing: inherit; caret-color: rgb(36, 39, 41); color: #242729; font-family: Arial, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; line-height: inherit; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
The expression inside&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;decltype&lt;/code&gt;&amp;nbsp;is explicitly excluded from template argument deduction. I guess this is because it can be arbitrarily complex.&lt;/div&gt;
&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
Even if we used a pattern without&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;decltype&lt;/code&gt;&amp;nbsp;like&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void_t&amp;lt; T &amp;gt;&lt;/code&gt;, then the deduction of&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;happens on the resolved alias template. That is, we resolve the alias template and then try to deduce the type&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;&amp;nbsp;from the resulting pattern. The resulting pattern however is&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void&lt;/code&gt;, which is not dependent on&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;&amp;nbsp;and therefore does not allow us to find a specific type for&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;T&lt;/code&gt;. This is similar to the mathematical problem of trying to invert a constant function (in the mathematical sense of those terms).&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Template argument deduction is finished&lt;sup style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 12px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: 1; margin: 0px; padding: 0px;&quot;&gt;(*)&lt;/sup&gt;, now the&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;deduced&lt;/span&gt;&amp;nbsp;template arguments are substituted. This creates a specialization that looks like this:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
The type&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;void_t&amp;lt; decltype( A::member ) &amp;gt; &amp;gt;&lt;/code&gt;&amp;nbsp;can now be evaluated. It is well-formed after substitution, hence, no&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Substitution Failure&lt;/span&gt;&amp;nbsp;occurs. We get:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
Now, we can compare the template parameter list of this specialization with the template arguments supplied to the original&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt;A&amp;gt;::value&lt;/code&gt;. Both types match exactly, so this partial specialization is chosen.&lt;/div&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
On the other hand, when we define the template as:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;border: 0px; box-sizing: inherit; color: #858c93; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;border: 0px; box-sizing: inherit; color: #2b91af; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
We end up with the same specialization:&lt;/div&gt;
&lt;pre class=&quot;lang-cpp prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
but our template argument list for&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;has_member&amp;lt;A&amp;gt;::value&lt;/code&gt;&amp;nbsp;now is&amp;nbsp;&lt;code style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&amp;lt;A, int&amp;gt;&lt;/code&gt;. The arguments do not match the parameters of the specialization, and the primary template is chosen as a fall-back.&lt;/div&gt;
&lt;hr style=&quot;background-color: #d6d9dc; border: 0px; box-sizing: inherit; color: #d6d9dc; height: 1px; margin-bottom: 20px;&quot; /&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;sup style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-size: 12px; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: 1; margin: 0px; padding: 0px;&quot;&gt;(*)&lt;/sup&gt;&amp;nbsp;The Standard, IMHO confusingly, includes the substitution process and the matching of explicitly specified template arguments in the&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;template argument deduction&lt;/span&gt;&amp;nbsp;process. For example (post-N4296) [temp.class.spec.match]/2:&lt;/div&gt;
&lt;blockquote style=&quot;background-color: cornsilk; border-left-color: rgb(255, 235, 142); border-left-style: solid; border-width: 0px 0px 0px 2px; box-sizing: inherit; font-stretch: inherit; line-height: inherit; margin: 0px 0px 10px; padding: 10px; quotes: none; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant-caps: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;&quot;&gt;
A partial specialization matches a given actual template argument list if the template arguments of the partial specialization can be deduced from the actual template argument list.&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div style=&quot;border: 0px; box-sizing: inherit; clear: both; font-stretch: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;&quot;&gt;
But this does not&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;just&lt;/span&gt;&amp;nbsp;mean that all template-parameters of the partial specialization have to be deduced; it also means that substitution must succeed and (as it seems?) the template arguments have to match the (substituted) template parameters of the partial specialization. Note that I&#39;m not completely aware of&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: italic; font-variant-caps: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;where&lt;/span&gt;&amp;nbsp;the Standard specifies the comparison between the substituted argument list and the supplied argument list.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/5700481190002940458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2018/12/stdvoidt.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/5700481190002940458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/5700481190002940458'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2018/12/stdvoidt.html' title='std::void_t'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-7842361654677500926</id><published>2018-12-08T11:36:00.001-08:00</published><updated>2018-12-08T20:53:55.995-08:00</updated><title type='text'></title><content type='html'>GNU format attributes&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.unixwiz.net/techtips/gnu-c-attributes.html&quot;&gt;__attribute__ format(printf, 2, 3)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/carlcook/variadicLogging/blob/master/main.cc&quot;&gt;a variadic logger&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/7842361654677500926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2018/12/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7842361654677500926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/7842361654677500926'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2018/12/blog-post.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-2615356213115280998</id><published>2018-11-25T09:06:00.001-08:00</published><updated>2018-11-26T20:59:58.368-08:00</updated><title type='text'></title><content type='html'>11/25/2018:&lt;br /&gt;
&lt;br /&gt;
1. C++ &amp;nbsp;sanitizers:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;ubsan: undefined behavior sanitizer&lt;/li&gt;
&lt;li&gt;&amp;nbsp;asan: &amp;nbsp;address sanitizer&lt;/li&gt;
&lt;li&gt;&amp;nbsp;tsan: &amp;nbsp;thread sanitizer&lt;/li&gt;
&lt;li&gt;&amp;nbsp;msan: memory sanitizer&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;
2. C++ open source codes:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;{fmt}&lt;/li&gt;
&lt;li&gt;spdlog&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;
3. C++ website:&lt;br /&gt;
3.1)&amp;nbsp;&lt;a href=&quot;https://godbolt.org/&quot;&gt;Compiler Explorer&lt;/a&gt;&lt;br /&gt;
3.2)&amp;nbsp;&lt;a href=&quot;https://cppinsights.io/&quot;&gt;Cpp insights&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
4.&amp;nbsp;&lt;a href=&quot;https://www.youtube.com/watch?v=nXaxk27zwlk&quot;&gt;CppCon 2015: Chandler Carruth &quot;Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!&quot;&lt;/a&gt;&lt;br /&gt;
&lt;h1 class=&quot;title style-scope ytd-video-primary-info-renderer&quot; style=&quot;border: 0px; color: var(--ytd-video-primary-info-renderer-title-color, var(--yt-primary-text-color)); font-family: Roboto, Arial, sans-serif; font-size: var(--ytd-video-primary-info-renderer-title-font-size, 1.8rem); font-variant: var(--ytd-video-primary-info-renderer-title-font-variant, inherit); font-weight: 400; line-height: 2.4rem; margin: 0px; max-height: 4.8rem; overflow: hidden; padding: 0px; text-shadow: var(--ytd-video-primary-info-renderer-title-text-shadow, none); transform: var(--ytd-video-primary-info-renderer-title-transform, none);&quot;&gt;
&lt;yt-formatted-string class=&quot;style-scope ytd-video-primary-info-renderer&quot; style=&quot;--yt-endpoint-color: hsl(206.1, 79.3%, 52.7%);&quot;&gt;&lt;/yt-formatted-string&gt;&lt;/h1&gt;
&lt;h1 class=&quot;title style-scope ytd-video-primary-info-renderer&quot; style=&quot;border: 0px; color: var(--ytd-video-primary-info-renderer-title-color, var(--yt-primary-text-color)); font-family: Roboto, Arial, sans-serif; font-size: var(--ytd-video-primary-info-renderer-title-font-size, 1.8rem); font-variant: var(--ytd-video-primary-info-renderer-title-font-variant, inherit); font-weight: 400; line-height: 2.4rem; margin: 0px; max-height: 4.8rem; overflow: hidden; padding: 0px; text-shadow: var(--ytd-video-primary-info-renderer-title-text-shadow, none); transform: var(--ytd-video-primary-info-renderer-title-transform, none);&quot;&gt;
&lt;yt-formatted-string class=&quot;style-scope ytd-video-primary-info-renderer&quot; style=&quot;--yt-endpoint-color: hsl(206.1, 79.3%, 52.7%);&quot;&gt;&lt;/yt-formatted-string&gt;&lt;/h1&gt;
</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/2615356213115280998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2018/11/11252018-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2615356213115280998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/2615356213115280998'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2018/11/11252018-1.html' title=''/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8445934432797432506.post-5732236994076393141</id><published>2018-11-08T20:54:00.000-08:00</published><updated>2018-11-11T07:01:32.401-08:00</updated><title type='text'>Understanding dynamic loading</title><content type='html'>&lt;a href=&quot;https://amir.rachum.com/blog/2016/09/17/shared-libraries/&quot;&gt;Shared Libraries: Understanding Dynamic Loading&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://cgold.readthedocs.io/en/latest/overview/cmake-can.html&quot; rel=&quot;nofollow&quot;&gt;CMake tutorial &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/&quot;&gt;Modern CMake&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://cliutils.gitlab.io/modern-cmake/&quot;&gt;An introduction of modern CMake&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://streetprogrammer.blogspot.com/feeds/5732236994076393141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://streetprogrammer.blogspot.com/2018/11/understanding-dynamic-loading.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/5732236994076393141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8445934432797432506/posts/default/5732236994076393141'/><link rel='alternate' type='text/html' href='http://streetprogrammer.blogspot.com/2018/11/understanding-dynamic-loading.html' title='Understanding dynamic loading'/><author><name>street programmer</name><uri>http://www.blogger.com/profile/16732277686886321937</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>