<story><title>Solving FizzBuzz with C++ compiler error messages</title><url>http://www.adampetersen.se/articles/fizzbuzz.htm</url></story><parent_chain></parent_chain><comment><author>kachuthan</author><text>How about a solution for primes below a number using Sieve of Eratosthenes:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  template&amp;#60;int H=-1, typename T=void&amp;#62;
  struct tl {
      enum {head=H};
      typedef T tail;
  };
  
  template&amp;#60;&amp;#62;
  struct tl&amp;#60;&amp;#62; {
  };
  
  template&amp;#60;int N, typename Then, typename Else&amp;#62;
  struct if_c {
      typedef Then type;
  };
  
  template&amp;#60;typename Then, typename Else&amp;#62;
  struct if_c&amp;#60;false, Then, Else&amp;#62; {
      typedef Else type;
  };
  
  template&amp;#60;int N, typename SoFar&amp;#62;
  struct is_prime {
      enum {value = N%SoFar::head &amp;#38;&amp;#38; is_prime&amp;#60;N, SoFar::tail&amp;#62;::value};
  };
  
  template&amp;#60;int N&amp;#62;
  struct is_prime&amp;#60;N, tl&amp;#60;&amp;#62;&amp;#62; {
      enum {value = 1};
  };
  
  template&amp;#60;int N, int C, typename SoFar=tl&amp;#60;&amp;#62;&amp;#62;
  struct prime {
      typedef typename prime&amp;#60;N+1, C-1, typename if_c&amp;#60;is_prime&amp;#60;N, SoFar&amp;#62;::value, tl&amp;#60;N, SoFar&amp;#62;, SoFar&amp;#62;::type&amp;#62;::type type;
  };
  
  template&amp;#60;int N, typename SoFar&amp;#62;
  struct prime&amp;#60;N, 0, SoFar&amp;#62; {
      typedef SoFar type;
  };
  
  template&amp;#60;int N&amp;#62;
  struct number : prime&amp;#60;2, N-2&amp;#62; {
  };
  
  template&amp;#60;&amp;#62;
  struct number&amp;#60;0&amp;#62; {
  };
  
  template&amp;#60;&amp;#62;
  struct number&amp;#60;1&amp;#62; {
  };
  
  template&amp;#60;typename T&amp;#62;
  struct print {
  };
  
  void main() {
      typedef print&amp;#60;number&amp;#60;300&amp;#62;::type&amp;#62;::type type;
  }

&lt;/code&gt;&lt;/pre&gt;
Here is result from Visual Studio 2005:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  c:\console.cpp(113) : error C2039: &apos;type&apos; : is not a member of &apos;print&amp;#60;T&amp;#62;&apos; with [T=tl&amp;#60;293,tl&amp;#60;283,tl&amp;#60;281,tl&amp;#60;277,tl&amp;#60;271,tl&amp;#60;269,tl&amp;#60;263,tl&amp;#60;257,tl&amp;#60;251,tl&amp;#60;241,tl&amp;#60;239,tl&amp;#60;233,tl&amp;#60;229,tl&amp;#60;227,tl&amp;#60;223,tl&amp;#60;211,tl&amp;#60;199,tl&amp;#60;197,tl&amp;#60;193,tl&amp;#60;191,tl&amp;#60;181,tl&amp;#60;179,tl&amp;#60;173,tl&amp;#60;167,tl&amp;#60;163,tl&amp;#60;157,tl&amp;#60;151,tl&amp;#60;149,tl&amp;#60;139,tl&amp;#60;137,tl&amp;#60;131,tl&amp;#60;127,tl&amp;#60;113,tl&amp;#60;109,tl&amp;#60;107,tl&amp;#60;103,tl&amp;#60;101,tl&amp;#60;97,tl&amp;#60;89,tl&amp;#60;83,tl&amp;#60;79,tl&amp;#60;73,tl&amp;#60;71,tl&amp;#60;67,tl&amp;#60;61,tl&amp;#60;59,tl&amp;#60;53,tl&amp;#60;47,tl&amp;#60;43,tl&amp;#60;41,tl&amp;#60;37,tl&amp;#60;31,tl&amp;#60;29,tl&amp;#60;23,tl&amp;#60;19,tl&amp;#60;17,tl&amp;#60;13,tl&amp;#60;11,tl&amp;#60;7,tl&amp;#60;5,tl&amp;#60;3,tl&amp;#60;2,tl&amp;#60;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;&amp;#62;]&lt;/code&gt;&lt;/pre&gt;</text></comment>
<story><title>Solving FizzBuzz with C++ compiler error messages</title><url>http://www.adampetersen.se/articles/fizzbuzz.htm</url></story><parent_chain></parent_chain><comment><author>kaeluka</author><text>You wouldn&apos;t pass, because you didn&apos;t read the specs!&lt;p&gt;&quot;prints the numbers from &lt;i&gt;&lt;/i&gt;1&lt;i&gt;&lt;/i&gt; to 100.&quot; -- you printed 0-100! ;-)&lt;p&gt;Just kidding, nice solution. Show&apos;s nicely how terrible and awesome the precompiler is.</text></comment>