Boost C++ Libraries: Ticket #799: mpl::if_ https://svn.boost.org/trac10/ticket/799 <pre class="wiki">There is an alternative implementation of mpl::if. This implementation makes code clearer. We can write: typename if_ &lt; X, Y &gt; ::else_if &lt; Z, U &gt; ::else_ &lt; V &gt;::type The implementation can be found here: http://cbear.berlios.de/meta/if.hpp </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/799 Trac 1.4.3 Dave Abrahams Fri, 06 Jul 2007 01:50:54 GMT status, resolution, description changed; severity set https://svn.boost.org/trac10/ticket/799#comment:1 https://svn.boost.org/trac10/ticket/799#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">invalid</span> </li> <li><strong>description</strong> modified (<a href="/trac10/ticket/799?action=diff&amp;version=1">diff</a>) </li> <li><strong>severity</strong> → <span class="trac-field-new">Showstopper</span> </li> </ul> <p> I disagree; it's far too verbose, and thus less clear, when you consider the need for the <code>template</code> keyword, which you left out. </p> <div class="wiki-code"><div class="code"><pre> <span class="k">typename</span> <span class="n">if_</span> <span class="o">&lt;</span> <span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">&gt;</span> <span class="o">::</span><span class="k">template</span> <span class="n">else_if</span> <span class="o">&lt;</span> <span class="n">Z</span><span class="p">,</span> <span class="n">U</span> <span class="o">&gt;</span> <span class="o">::</span><span class="k">template</span> <span class="n">else_</span> <span class="o">&lt;</span> <span class="n">V</span> <span class="o">&gt;::</span><span class="n">type</span> </pre></div></div> Ticket anonymous Wed, 05 Sep 2007 08:22:19 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/799#comment:2 https://svn.boost.org/trac10/ticket/799#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/799#comment:1" title="Comment 1">dave</a>: </p> <blockquote class="citation"> <p> I disagree; it's far too verbose, and thus less clear, when you consider the need for the <code>template</code> keyword, which you left out. </p> </blockquote> <p> Ok, lets compare: </p> <p> 1 condition: </p> <div class="wiki-code"><div class="code"><pre><span class="c1">// Boost</span> <span class="k">typedef</span> <span class="n">Mpl</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">C</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">E</span><span class="o">&gt;::</span><span class="n">type</span> <span class="n">X</span><span class="p">;</span> <span class="c1">// cbear</span> <span class="k">typedef</span> <span class="n">Meta</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">C</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">E</span><span class="o">&gt;::</span><span class="n">type</span> <span class="n">X</span><span class="p">;</span> </pre></div></div><p> 5 conditions: </p> <div class="wiki-code"><div class="code"><pre><span class="c1">// Boost</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">C1</span><span class="p">,</span> <span class="k">class</span> <span class="nc">C2</span><span class="p">,</span> <span class="k">class</span> <span class="nc">C3</span><span class="p">,</span> <span class="k">class</span> <span class="nc">C4</span><span class="p">,</span> <span class="k">class</span> <span class="nc">C5</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="nl">X</span><span class="p">:</span> <span class="n">Mpl</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">C1</span><span class="p">,</span> <span class="n">T1</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Mpl</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">C2</span><span class="p">,</span> <span class="n">T2</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Mpl</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">C3</span><span class="p">,</span> <span class="n">T3</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Mpl</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">C4</span><span class="p">,</span> <span class="n">T4</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Mpl</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">C5</span><span class="p">,</span> <span class="n">T5</span><span class="p">,</span> <span class="n">E</span> <span class="o">&gt;::</span><span class="n">type</span> <span class="o">&gt;::</span><span class="n">type</span> <span class="o">&gt;::</span><span class="n">type</span> <span class="o">&gt;::</span><span class="n">type</span> <span class="o">&gt;</span> <span class="p">{</span> <span class="p">};</span> <span class="c1">// cbear</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">C1</span><span class="p">,</span> <span class="k">class</span> <span class="nc">C2</span><span class="p">,</span> <span class="k">class</span> <span class="nc">C3</span><span class="p">,</span> <span class="k">class</span> <span class="nc">C4</span><span class="p">,</span> <span class="k">class</span> <span class="nc">C5</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="nl">X</span><span class="p">:</span> <span class="n">Meta</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">C1</span><span class="p">,</span> <span class="n">T1</span><span class="o">&gt;::</span> <span class="k">template</span> <span class="n">else_if</span><span class="o">&lt;</span><span class="n">C2</span><span class="p">,</span> <span class="n">T2</span><span class="o">&gt;::</span> <span class="k">template</span> <span class="n">else_if</span><span class="o">&lt;</span><span class="n">C3</span><span class="p">,</span> <span class="n">T3</span><span class="o">&gt;::</span> <span class="k">template</span> <span class="n">else_if</span><span class="o">&lt;</span><span class="n">C4</span><span class="p">,</span> <span class="n">T4</span><span class="o">&gt;::</span> <span class="k">template</span> <span class="n">else_if</span><span class="o">&lt;</span><span class="n">C5</span><span class="p">,</span> <span class="n">T5</span><span class="o">&gt;::</span> <span class="k">template</span> <span class="n">else_</span><span class="o">&lt;</span><span class="n">E</span><span class="o">&gt;</span> <span class="p">{</span> <span class="p">};</span> </pre></div></div><p> enable if T is integer: </p> <div class="wiki-code"><div class="code"><pre><span class="c1">// Boost</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span> <span class="n">T</span> <span class="n">foo</span><span class="p">(</span><span class="n">T</span> <span class="n">t</span><span class="p">,</span> <span class="k">typename</span> <span class="n">boost</span><span class="o">::</span><span class="n">enable_if</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">is_integral</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="o">&gt;::</span><span class="n">type</span><span class="o">*</span> <span class="n">dummy</span> <span class="o">=</span> <span class="mi">0</span><span class="p">);</span> <span class="c1">// cbear</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span> <span class="n">T</span> <span class="n">foo</span><span class="p">(</span><span class="n">T</span> <span class="n">t</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Meta</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">is_integral</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="o">&gt;::</span><span class="n">type</span><span class="o">*</span> <span class="n">dummy</span> <span class="o">=</span> <span class="mi">0</span><span class="p">);</span> </pre></div></div><p> enable if T is integer (returns T) or pointer (returns int): </p> <div class="wiki-code"><div class="code"><pre><span class="c1">// Boost</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span> <span class="k">typename</span> <span class="n">Mpl</span><span class="o">::</span><span class="n">lazy_enable_if</span><span class="o">&lt;</span> <span class="n">Mpl</span><span class="o">::</span><span class="n">or_</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">is_integral</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">is_pointer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="o">&gt;</span><span class="p">,</span> <span class="c1">// !!!</span> <span class="n">Mpl</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">is_integral</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="kt">int</span><span class="o">&gt;</span> <span class="o">&gt;::</span><span class="n">type</span> <span class="n">foo</span><span class="p">(</span><span class="n">T</span> <span class="n">t</span><span class="p">);</span> <span class="c1">// cbear</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span> <span class="k">typename</span> <span class="n">Meta</span><span class="o">::</span><span class="n">if_</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">is_integral</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">,</span> <span class="n">T</span><span class="o">&gt;::</span> <span class="k">template</span> <span class="n">else_if</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">is_pointer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">,</span> <span class="kt">int</span><span class="o">&gt;::</span><span class="n">type</span> <span class="n">foo</span><span class="p">(</span><span class="n">T</span> <span class="n">t</span><span class="p">);</span> </pre></div></div><p> I would agree with some other arguments. But not with 'it's far too verbose, and thus less clear'. That's false! </p> Ticket Dave Abrahams Wed, 05 Sep 2007 21:07:06 GMT owner, status changed https://svn.boost.org/trac10/ticket/799#comment:3 https://svn.boost.org/trac10/ticket/799#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">nobody</span> to <span class="trac-author">Aleksey Gurtovoy</span> </li> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> <p> Sorry, I hadn't looked at your implementation, so I assumed that you had to use <code>else_</code> rather than a third argument. I'm beginning to like your suggestion. We'll have to see what Aleksey says. </p> Ticket Aleksey Gurtovoy Thu, 06 Sep 2007 05:33:27 GMT status changed https://svn.boost.org/trac10/ticket/799#comment:4 https://svn.boost.org/trac10/ticket/799#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> It's a nice extension, I like it. Let's get it in. </p> Ticket sergey.junk@… Thu, 06 Sep 2007 06:08:07 GMT <link>https://svn.boost.org/trac10/ticket/799#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/799#comment:5</guid> <description> <p> Note: it also replaces lazy_enable_if (if_), and enable_if (if_c). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dave Abrahams</dc:creator> <pubDate>Thu, 06 Sep 2007 10:38:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/799#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/799#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/799#comment:5" title="Comment 5">sergey.junk@comrades.id.ua</a>: </p> <blockquote class="citation"> <p> Note: it also replaces lazy_enable_if (if_), and enable_if (if_c). </p> </blockquote> <p> I know, and I like the way it does that, too. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 06 Sep 2007 13:45:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/799#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/799#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/799#comment:6" title="Comment 6">dave</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/799#comment:5" title="Comment 5">sergey.junk@comrades.id.ua</a>: </p> <blockquote class="citation"> <p> Note: it also replaces lazy_enable_if (if_), and enable_if (if_c). </p> </blockquote> <p> I know, and I like the way it does that, too. </p> </blockquote> <p> In case berlios.de dosn't work, see <a class="ext-link" href="http://cbear.svn.sourceforge.net/viewvc/cbear/trunk/cbear.berlios.de/meta/if.hpp?revision=8&amp;view=markup&amp;pathrev=13"><span class="icon">​</span>http://cbear.svn.sourceforge.net/viewvc/cbear/trunk/cbear.berlios.de/meta/if.hpp?revision=8&amp;view=markup&amp;pathrev=13</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dave Abrahams</dc:creator> <pubDate>Thu, 25 Oct 2007 23:11:56 GMT</pubDate> <title>component changed https://svn.boost.org/trac10/ticket/799#comment:8 https://svn.boost.org/trac10/ticket/799#comment:8 <ul> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">mpl</span> </li> </ul> Ticket Daniel James Wed, 13 May 2009 06:46:30 GMT severity changed https://svn.boost.org/trac10/ticket/799#comment:9 https://svn.boost.org/trac10/ticket/799#comment:9 <ul> <li><strong>severity</strong> <span class="trac-field-old">Showstopper</span> → <span class="trac-field-new">Problem</span> </li> </ul> Ticket anonymous Mon, 03 Jan 2011 17:53:31 GMT owner, status changed https://svn.boost.org/trac10/ticket/799#comment:10 https://svn.boost.org/trac10/ticket/799#comment:10 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Aleksey Gurtovoy</span> to <span class="trac-author">Joel Falcou</span> </li> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket Joel Falcou Mon, 03 Jan 2011 17:55:58 GMT version changed; cc, milestone set https://svn.boost.org/trac10/ticket/799#comment:11 https://svn.boost.org/trac10/ticket/799#comment:11 <ul> <li><strong>cc</strong> <span class="trac-author">joel.falcou@…</span> added </li> <li><strong>version</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">Boost 1.45.0</span> </li> <li><strong>milestone</strong> → <span class="trac-field-new">Boost 1.46.0</span> </li> </ul> Ticket NN Thu, 06 Jan 2011 10:33:31 GMT <link>https://svn.boost.org/trac10/ticket/799#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/799#comment:12</guid> <description> <p> This is a very good alternative. I wish boost had this feature. </p> </description> <category>Ticket</category> </item> </channel> </rss>