<?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/"
		>
<channel>
	<title>Comments on: Generators in C++</title>
	<atom:link href="http://www.terrainformatica.com/2008/05/generators-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.terrainformatica.com/index.php/2008/05/generators-in-c/</link>
	<description>Terra Informatica, home of embeddable html and CSS rendering engines.</description>
	<lastBuildDate>Fri, 08 Apr 2011 07:40:02 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Andrew</title>
		<link>http://www.terrainformatica.com/index.php/2008/05/generators-in-c/comment-page-1/#comment-4841</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Tue, 30 Sep 2008 22:14:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.terrainformatica.com/index.php/?p=97#comment-4841</guid>
		<description>Here is what I&#039;ve ended up with:

&lt;pre&gt;struct _generator
  {
    int _line;
    _generator() { rewind(); }
    void rewind() { _line = 0; }
  };

  #define $generator(NAME) struct NAME : public tool::_generator

  #define $emit(T)       bool operator()(T&amp; _rv) { switch(_line) { case 0:;
  #define $emit2(T1,T2)  bool operator()(T1&amp; _rv1, T2&amp; _rv2) { switch(_line) { case 0:;
  
  #define $yield(V)      { _line=__LINE__; _rv = (V); return true; case __LINE__: _line=__LINE__; }
  #define $yield2(V1,V2) { _line=__LINE__; _rv1 = (V1); _rv2 = (V2); return true; case __LINE__: _line=__LINE__; }

  #define $stop  } _line = 0; return false; }&lt;/pre&gt;

It also has $yield2 when you need to emit two values.</description>
		<content:encoded><![CDATA[<p>Here is what I&#8217;ve ended up with:</p>
<pre>struct _generator
  {
    int _line;
    _generator() { rewind(); }
    void rewind() { _line = 0; }
  };

  #define $generator(NAME) struct NAME : public tool::_generator

  #define $emit(T)       bool operator()(T&#038; _rv) { switch(_line) { case 0:;
  #define $emit2(T1,T2)  bool operator()(T1&#038; _rv1, T2&#038; _rv2) { switch(_line) { case 0:;

  #define $yield(V)      { _line=__LINE__; _rv = (V); return true; case __LINE__: _line=__LINE__; }
  #define $yield2(V1,V2) { _line=__LINE__; _rv1 = (V1); _rv2 = (V2); return true; case __LINE__: _line=__LINE__; }

  #define $stop  } _line = 0; return false; }</pre>
<p>It also has $yield2 when you need to emit two values.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.terrainformatica.com/index.php/2008/05/generators-in-c/comment-page-1/#comment-4840</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Tue, 30 Sep 2008 22:10:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.terrainformatica.com/index.php/?p=97#comment-4840</guid>
		<description>Yes, in principle it could be just scope block:

&lt;pre&gt;#define yield(V) {\\
   _line=__LINE__; \\
   _rv = (V); return true; case __LINE__: _line=__LINE__;\\
 }&lt;/pre&gt;

Simon initially used do/while(0) so I just left it &quot;as is&quot;.

But some form of &#039;{&#039; &#039;}&#039; brackets is definitely needed there to
handle properly things like if(condition) $yield(something);</description>
		<content:encoded><![CDATA[<p>Yes, in principle it could be just scope block:</p>
<pre>#define yield(V) {\\
   _line=__LINE__; \\
   _rv = (V); return true; case __LINE__: _line=__LINE__;\\
 }</pre>
<p>Simon initially used do/while(0) so I just left it &#8220;as is&#8221;.</p>
<p>But some form of &#8216;{&#8216; &#8216;}&#8217; brackets is definitely needed there to<br />
handle properly things like if(condition) $yield(something);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick</title>
		<link>http://www.terrainformatica.com/index.php/2008/05/generators-in-c/comment-page-1/#comment-4837</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Tue, 30 Sep 2008 19:40:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.terrainformatica.com/index.php/?p=97#comment-4837</guid>
		<description>why &quot;do&quot; end &quot;while (0)
in yield ?</description>
		<content:encoded><![CDATA[<p>why &#8220;do&#8221; end &#8220;while (0)<br />
in yield ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Terra Informatica &#187; Generators in C++ revisited.</title>
		<link>http://www.terrainformatica.com/index.php/2008/05/generators-in-c/comment-page-1/#comment-3424</link>
		<dc:creator>Terra Informatica &#187; Generators in C++ revisited.</dc:creator>
		<pubDate>Thu, 26 Jun 2008 15:00:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.terrainformatica.com/index.php/?p=97#comment-3424</guid>
		<description>[...] Previous version of generators had design problem - it required some special stop value. That is the same kind of problem as with iterators in C++. In some cases it is not possible to choose such a value. [...]</description>
		<content:encoded><![CDATA[<p>[...] Previous version of generators had design problem &#8211; it required some special stop value. That is the same kind of problem as with iterators in C++. In some cases it is not possible to choose such a value. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: metalliova</title>
		<link>http://www.terrainformatica.com/index.php/2008/05/generators-in-c/comment-page-1/#comment-3372</link>
		<dc:creator>metalliova</dc:creator>
		<pubDate>Mon, 23 Jun 2008 23:29:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.terrainformatica.com/index.php/?p=97#comment-3372</guid>
		<description>I do not think that it may boost development. Take into account, plase, that this approach forces a developer to know how it&#039;s implemented. Needless to say that it uses MACROs!!! The idea is great, somehow</description>
		<content:encoded><![CDATA[<p>I do not think that it may boost development. Take into account, plase, that this approach forces a developer to know how it&#8217;s implemented. Needless to say that it uses MACROs!!! The idea is great, somehow</p>
]]></content:encoded>
	</item>
</channel>
</rss>

