title: Improving a variadic template function using new c++14 / c++17 features
body: <p>I am newbie to variadic templates, still I managed to program some code in c++11 using it, but I still feel sour about result because it lacks expressivity.</p>
  <p>The issue is to implement a function that accept several <code>bool</code> conditions (from <code>1</code> to whatever) and returns an integer code indicating in what place is the first &quot;<code>false</code>&quot; argument, or <code>0</code> if all of them are <code>true</code>.</p>
  <pre><code>e.g. &quot;error_code(true, true, true);&quot; must return 0
  e.g. &quot;error_code(true, true, false);&quot; must return 3
  e.g. &quot;error_code(true, false, false);&quot; must return 2
  e.g. &quot;error_code(false, false, false);&quot; must return 1
  </code></pre>
  <p>My current code stands for (live link to coliru: <a href="http://coliru.stacked-crooked.com/a/1b557f2819ae9775" rel="nofollow noreferrer">http://coliru.stacked-crooked.com/a/1b557f2819ae9775</a>):</p>
  <pre><code>#include &lt;tuple&gt;
  #include &lt;iostream&gt;
  
  int error_impl(bool cond)
  {
      return cond;
  }
  
  template&lt;typename... Args&gt;
  int error_impl(bool cond, Args... args)
  {
      return cond ? 1 + error_impl(args...) : 0;
  }
  
  template&lt;typename... Args&gt;
  int error_code(Args... args)
  {
      constexpr std::size_t size = std::tuple_size&lt;std::tuple&lt;Args...&gt;&gt;::value + 1;
      return (error_impl(args...) + 1) % size;
  }
  
  int main()
  {
      auto e1 = error_code(true, true, true);
      auto e2 = error_code(true, true, false);
      auto e3 = error_code(true, false, false);
      auto e4 = error_code(false, false, false);
      std::cout &lt;&lt; std::boolalpha;
      std::cout &lt;&lt; &quot;(true, true, true)==0 -&gt; &quot; &lt;&lt; (e1 == 0) &lt;&lt; &quot;\n&quot;;
      std::cout &lt;&lt; &quot;(true, true, false)==3 -&gt; &quot; &lt;&lt; (e2 == 3) &lt;&lt; &quot;\n&quot;;
      std::cout &lt;&lt; &quot;(true, false, false)==2 -&gt; &quot; &lt;&lt; (e3 == 2)&lt;&lt; &quot;\n&quot;;
      std::cout &lt;&lt; &quot;(false, false, false)==1 -&gt; &quot; &lt;&lt; (e4 == 1)&lt;&lt; &quot;\n&quot;;
  
      auto e5 = error_code(true, true, true, true);
      auto e6 = error_code(true, true, true, false);
      auto e7 = error_code(true, true, false, false);
      auto e8 = error_code(true, false, false, false);
      auto e9 = error_code(false, false, false, false);
      std::cout &lt;&lt; &quot;(true, true, true, true)==0 -&gt; &quot; &lt;&lt; (e5 == 0) &lt;&lt; &quot;\n&quot;;
      std::cout &lt;&lt; &quot;(true, true, true, false)==4 -&gt; &quot; &lt;&lt; (e6 == 4) &lt;&lt; &quot;\n&quot;;
      std::cout &lt;&lt; &quot;(true, true, false, false)==3 -&gt; &quot; &lt;&lt; (e7 == 3) &lt;&lt; &quot;\n&quot;;
      std::cout &lt;&lt; &quot;(true, false, false, false)==2 -&gt; &quot; &lt;&lt; (e8 == 2)&lt;&lt; &quot;\n&quot;;
      std::cout &lt;&lt; &quot;(false, false, false, false)==1 -&gt; &quot; &lt;&lt; (e9 == 1)&lt;&lt; &quot;\n&quot;;
  }
  </code></pre>
  <p>I wonder where this &quot;<code>error_code()</code>&quot; function can be improved using new unroll features from c++14 / c++17, so it gains in expressivity and uses less than 3 functions.</p>
  <p>Any help will be grateful welcomed!</p>