<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments for cplusplus.co.il</title>
	<atom:link href="http://cplusplus.co.il/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://cplusplus.co.il</link>
	<description>Discussing modern C++ and related topics.</description>
	<lastBuildDate>Wed, 21 Jul 2010 15:13:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>Comment on Variadic macro to count number of arguments by kcb</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-500</link>
		<dc:creator>kcb</dc:creator>
		<pubDate>Wed, 21 Jul 2010 15:13:13 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-500</guid>
		<description>You can actually work around the zero-argument limitation by utilizing stringification:

[sourcecode language=&quot;cpp&quot;]
#define VA_NUM_ARGS(...) \
    (sizeof(#__VA_ARGS__) == sizeof(&quot;&quot;) \
     ? 0 : VA_NUM_ARGS_IMPL(__VA_ARGS__, 5,4,3,2,1))
[/sourcecode]

This will be evaluated as a constant expression by the compiler.  Since the preprocessor removes all extra whitespace, an empty argument list will always become a zero-length string.</description>
		<content:encoded><![CDATA[<p>You can actually work around the zero-argument limitation by utilizing stringification:</p>
<pre class="brush: cpp;">
#define VA_NUM_ARGS(...) \
    (sizeof(#__VA_ARGS__) == sizeof(&quot;&quot;) \
     ? 0 : VA_NUM_ARGS_IMPL(__VA_ARGS__, 5,4,3,2,1))
</pre>
<p>This will be evaluated as a constant expression by the compiler.  Since the preprocessor removes all extra whitespace, an empty argument list will always become a zero-length string.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Variadic macro to count number of arguments by NN</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-499</link>
		<dc:creator>NN</dc:creator>
		<pubDate>Mon, 19 Jul 2010 07:53:52 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-499</guid>
		<description>You can use tuple in preprocessor:

BUILD_FACTORY(Object, (int)(vector))

It is nicer than second but uglier than first.
On the other hand it works for all compilers.


P.S.
Talking about Factory pattern, are you familiar with auto-registering approach ?
I mean that you don&#039;t have manually add types to the factory. :)</description>
		<content:encoded><![CDATA[<p>You can use tuple in preprocessor:</p>
<p>BUILD_FACTORY(Object, (int)(vector))</p>
<p>It is nicer than second but uglier than first.<br />
On the other hand it works for all compilers.</p>
<p>P.S.<br />
Talking about Factory pattern, are you familiar with auto-registering approach ?<br />
I mean that you don&#8217;t have manually add types to the factory. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Variadic macro to count number of arguments by NN</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-498</link>
		<dc:creator>NN</dc:creator>
		<pubDate>Mon, 19 Jul 2010 07:51:16 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-498</guid>
		<description>I agree, varying number of arguments approach is interesting.

I think Boost Preprocessor should starting using VA_ARGS since all popular compilers support this feature.

Btw, your approach with max is not scalable.
You have to define all maxN variations. :(</description>
		<content:encoded><![CDATA[<p>I agree, varying number of arguments approach is interesting.</p>
<p>I think Boost Preprocessor should starting using VA_ARGS since all popular compilers support this feature.</p>
<p>Btw, your approach with max is not scalable.<br />
You have to define all maxN variations. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Variadic macro to count number of arguments by Ofek Shilon</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-497</link>
		<dc:creator>Ofek Shilon</dc:creator>
		<pubDate>Sun, 18 Jul 2010 18:24:22 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-497</guid>
		<description>Nice!</description>
		<content:encoded><![CDATA[<p>Nice!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Variadic macro to count number of arguments by rmn</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-496</link>
		<dc:creator>rmn</dc:creator>
		<pubDate>Sun, 18 Jul 2010 12:10:28 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-496</guid>
		<description>Indeed that example of boost.pp ( http://www.afs.enea.it/aprea/boost_1_34_1/libs/preprocessor/doc/ref/max_d.html ) is pretty similar to what we&#039;re doing, but I think that anybody can see that using boost.pp&#039;s list is a lot more awkward than just using max() with a varying number of arguments as enabled here.
Another benefit of this post lies in the fact that it presents another approach to macros and shows some of their less known possibilities.</description>
		<content:encoded><![CDATA[<p>Indeed that example of boost.pp ( <a href="http://www.afs.enea.it/aprea/boost_1_34_1/libs/preprocessor/doc/ref/max_d.html" rel="nofollow">http://www.afs.enea.it/aprea/boost_1_34_1/libs/preprocessor/doc/ref/max_d.html</a> ) is pretty similar to what we&#8217;re doing, but I think that anybody can see that using boost.pp&#8217;s list is a lot more awkward than just using max() with a varying number of arguments as enabled here.<br />
Another benefit of this post lies in the fact that it presents another approach to macros and shows some of their less known possibilities.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Variadic macro to count number of arguments by Christopher Jefferson</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-495</link>
		<dc:creator>Christopher Jefferson</dc:creator>
		<pubDate>Sun, 18 Jul 2010 08:40:24 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-495</guid>
		<description>No, don&#039;t worry, I know about Boost.Tuple. For my example I was just simplifying out some details. In practice I am building a generic kind of Factory class. Internally I do actually make use of std::tuple and variadic templates, but that would just add more confusion!

While we possibly could do these things with Boost.Preprocessor, I find it nicer to ask people to write:

BUILD_FACTORY(Object, int, vector)

Than:

BUILD_FACTORY(Object, (int, (vector, (BOOST_PP_NIL))))

Also, if I use Boost.Preprocessor, I find all the iteration functionality to be very nasty. Long ago I implemented tr1::tuple for g++, and started using boost.preprocessor. In the end I ended up reimplementing the bits of it I wanted, as it is very complex to read.

Hopefully much of it, particularly to do with looping, could be reimplemented and simplified now we have variadic macros.</description>
		<content:encoded><![CDATA[<p>No, don&#8217;t worry, I know about Boost.Tuple. For my example I was just simplifying out some details. In practice I am building a generic kind of Factory class. Internally I do actually make use of std::tuple and variadic templates, but that would just add more confusion!</p>
<p>While we possibly could do these things with Boost.Preprocessor, I find it nicer to ask people to write:</p>
<p>BUILD_FACTORY(Object, int, vector)</p>
<p>Than:</p>
<p>BUILD_FACTORY(Object, (int, (vector, (BOOST_PP_NIL))))</p>
<p>Also, if I use Boost.Preprocessor, I find all the iteration functionality to be very nasty. Long ago I implemented tr1::tuple for g++, and started using boost.preprocessor. In the end I ended up reimplementing the bits of it I wanted, as it is very complex to read.</p>
<p>Hopefully much of it, particularly to do with looping, could be reimplemented and simplified now we have variadic macros.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Variadic macro to count number of arguments by NN</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-494</link>
		<dc:creator>NN</dc:creator>
		<pubDate>Sun, 18 Jul 2010 07:13:02 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-494</guid>
		<description>For max element you can just use Boost.Preprocessor:

[sourcecode language=&quot;cpp&quot;]
#include &lt;boost/preprocessor/list/fold_left.hpp&gt;
#include &lt;boost/preprocessor/selection/max.hpp&gt;

#define LIST (1, (3, (5, (2, (4, BOOST_PP_NIL)))))

#define OP(d, state, x) BOOST_PP_MAX_D(d, state, x)

#define LIST_MAX(list) BOOST_PP_LIST_FOLD_LEFT(OP, 0, LIST)

LIST_MAX(LIST) // expands to 5
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>For max element you can just use Boost.Preprocessor:</p>
<pre class="brush: cpp;">
#include &lt;boost/preprocessor/list/fold_left.hpp&gt;
#include &lt;boost/preprocessor/selection/max.hpp&gt;

#define LIST (1, (3, (5, (2, (4, BOOST_PP_NIL)))))

#define OP(d, state, x) BOOST_PP_MAX_D(d, state, x)

#define LIST_MAX(list) BOOST_PP_LIST_FOLD_LEFT(OP, 0, LIST)

LIST_MAX(LIST) // expands to 5
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Variadic macro to count number of arguments by NN</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-493</link>
		<dc:creator>NN</dc:creator>
		<pubDate>Sun, 18 Jul 2010 07:04:59 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-493</guid>
		<description>Here you should use Boost.Preprocessor.
It allows you what you need.

On the other hand it seems that you invent Boost.Tuple :)</description>
		<content:encoded><![CDATA[<p>Here you should use Boost.Preprocessor.<br />
It allows you what you need.</p>
<p>On the other hand it seems that you invent Boost.Tuple <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Variadic macro to count number of arguments by rmn</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-492</link>
		<dc:creator>rmn</dc:creator>
		<pubDate>Sat, 17 Jul 2010 11:42:17 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-492</guid>
		<description>Indeed, your example illustrates a great use case for the proposed construct. I was also thinking in these directions, and I think we could essentially make it a lot more general.

Let us create the following macro dispatcher, which takes a macro name and its arguments, and generates the proper call:
[sourcecode language=&quot;cpp&quot;]
#define macro_dispatcher(func, ...) \
            macro_dispatcher_(func, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(func, nargs) \
            macro_dispatcher__(func, nargs)
#define macro_dispatcher__(func, nargs) \
            func ## nargs
[/sourcecode]
(It requires two more levels of indirection due to the nature of the preprocessor).

Then, we could use it for &quot;overloading&quot; macros like you suggested. For example, here is how we would implement a MAX macro which accepts a varying number of arguments:
[sourcecode language=&quot;cpp&quot;]
#define max(...) macro_dispatcher(max, __VA_ARGS__)(__VA_ARGS__)

#define max1(a) a
#define max2(a,b) ((a)&gt;(b)?(a):(b))
#define max3(a,b,c) max2(max2(a,b),c)
// ...

// to verify, run the preprocessor alone (g++ -E):
max(1,2,3);
[/sourcecode]

Then, we are able to implement a solution to your problem in the same way, without writing too much code:
[sourcecode language=&quot;cpp&quot;]
#define BIG_CLASS(...) \
            macro_dispatcher(BIG_CLASS, __VA_ARGS__)(__VA_ARGS__)

#define BIG_CLASS3 /* Your example */
[/sourcecode]

I think this is pretty handy, useful, and general at the same time.</description>
		<content:encoded><![CDATA[<p>Indeed, your example illustrates a great use case for the proposed construct. I was also thinking in these directions, and I think we could essentially make it a lot more general.</p>
<p>Let us create the following macro dispatcher, which takes a macro name and its arguments, and generates the proper call:</p>
<pre class="brush: cpp;">
#define macro_dispatcher(func, ...) \
            macro_dispatcher_(func, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(func, nargs) \
            macro_dispatcher__(func, nargs)
#define macro_dispatcher__(func, nargs) \
            func ## nargs
</pre>
<p>(It requires two more levels of indirection due to the nature of the preprocessor).</p>
<p>Then, we could use it for &#8220;overloading&#8221; macros like you suggested. For example, here is how we would implement a MAX macro which accepts a varying number of arguments:</p>
<pre class="brush: cpp;">
#define max(...) macro_dispatcher(max, __VA_ARGS__)(__VA_ARGS__)

#define max1(a) a
#define max2(a,b) ((a)&gt;(b)?(a):(b))
#define max3(a,b,c) max2(max2(a,b),c)
// ...

// to verify, run the preprocessor alone (g++ -E):
max(1,2,3);
</pre>
<p>Then, we are able to implement a solution to your problem in the same way, without writing too much code:</p>
<pre class="brush: cpp;">
#define BIG_CLASS(...) \
            macro_dispatcher(BIG_CLASS, __VA_ARGS__)(__VA_ARGS__)

#define BIG_CLASS3 /* Your example */
</pre>
<p>I think this is pretty handy, useful, and general at the same time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Variadic macro to count number of arguments by Christopher Jefferson</title>
		<link>http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-491</link>
		<dc:creator>Christopher Jefferson</dc:creator>
		<pubDate>Sat, 17 Jul 2010 10:03:49 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=1003#comment-491</guid>
		<description>I can suggest a case where it is useful, as I have a problem I was just working on :)

I have a macro designed to build a class which looks like (simplifying, the full thing is much nastier, here is the case for &quot;2&quot; arguments).

[sourcecode language=&quot;cpp&quot;]
  #define BIG_CLASS2(name, Type1, Type2) \
  class name ## Box \
  {
    Type1 t1; \
    Type2 t2; \
    template &lt;typename T1, typename T2&gt;\
    name##Box(T1 _t1, T2 _t2) : t1(_t1), t2(_t2) {} \
  };\
[/sourcecode]

While I probably could write a macro that could produce this for any size, it&#039;s tricky to get things like the &quot;typename T1, typename T2&quot; to come out right, and I never need this bigger than 5, so I&#039;m happy to just write them out.

However, it is a bit annoying that I have to tell people to put the 1,2,.. at the start of the name, and will be nice to be able to remove it.</description>
		<content:encoded><![CDATA[<p>I can suggest a case where it is useful, as I have a problem I was just working on <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I have a macro designed to build a class which looks like (simplifying, the full thing is much nastier, here is the case for &#8220;2&#8243; arguments).</p>
<pre class="brush: cpp;">
  #define BIG_CLASS2(name, Type1, Type2) \
  class name ## Box \
  {
    Type1 t1; \
    Type2 t2; \
    template &lt;typename T1, typename T2&gt;\
    name##Box(T1 _t1, T2 _t2) : t1(_t1), t2(_t2) {} \
  };\
</pre>
<p>While I probably could write a macro that could produce this for any size, it&#8217;s tricky to get things like the &#8220;typename T1, typename T2&#8243; to come out right, and I never need this bigger than 5, so I&#8217;m happy to just write them out.</p>
<p>However, it is a bit annoying that I have to tell people to put the 1,2,.. at the start of the name, and will be nice to be able to remove it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
