<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2011:04:08</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Sun, 26 Apr 2026 13:28:38 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>1</title>
            <link>https://baszerr.eu/doku.php?id=blog:2011:04:08:1</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;template_overloading_for_array_types&quot;&gt;2011.04.08 - template overloading for array types&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
yesterday Mariusz, a friend from my &lt;a href=&quot;http://www.wcss.wroc.pl&quot; class=&quot;urlextern&quot; title=&quot;http://www.wcss.wroc.pl&quot; rel=&quot;ugc nofollow&quot;&gt;current work&lt;/a&gt;, showed me a short article describing interesting feature of &lt;a href=&quot;https://en.wikipedia.org/wiki/C++&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/C++&quot;&gt;C++&lt;/a&gt; – template overloading for array types. it&amp;#039;s very nice thing, since you can easily tell smart pointer if argument it takes is a pointer to some object or array of objects (i.e. “new X” or “new X[10]”, that both are pointer to by “X*”). for example consider the following code:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;
&amp;nbsp;
using namespace std&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
template&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;typename T&lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; Test
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; f&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    cout&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;Test&amp;lt;T&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;endl&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
template&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;typename T&lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; Test&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; f&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    cout&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;Test&amp;lt;T[]&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;endl&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  Test&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;*&amp;gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  Test&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
output on the screen is be:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;Test&amp;lt;T&amp;gt;
Test&amp;lt;T[]&amp;gt;&lt;/pre&gt;

&lt;p&gt;
another interesting fact is that it is actually used in &lt;a href=&quot;https://en.wikipedia.org/wiki/C++0x&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/C++0x&quot;&gt;C++0x&lt;/a&gt; standard library implementation of std::unique_ptr&amp;lt;&amp;gt;, to use “delete” for object pointers and “delete[]” for array-of-objects pointers.
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:09:39 +0000</pubDate>
        </item>
    </channel>
</rss>
