<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2012:12:11</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Fri, 01 May 2026 05:33:53 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>1</title>
            <link>https://baszerr.eu/doku.php?id=blog:2012:12:11:1</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;lambdas_vs_variadic_templates&quot;&gt;2012.12.11 - lambdas vs. variadic templates&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
few days ago at work i had a need to write error handling mechanism in multiple methods. the thing was, that the methods themselves were short (usually 2-3 lines), while error handling consisted of multiple catch-es and some logging.  there was also an &lt;em&gt;if(enabled)&lt;/em&gt; to be added at the beginning. well – excellent place for lambda! relevant fragment of the &lt;a href=&quot;https://baszerr.eu/lib/exe/fetch.php?media=blog:2012:12:11:example_handler.cpp&quot; class=&quot;media mediafile mf_cpp&quot; title=&quot;blog:2012:12:11:example_handler.cpp (802 B)&quot;&gt;example handler program&lt;/a&gt; follows:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;typename&lt;/span&gt; F&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; errHandler&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;F f, &lt;span class=&quot;kw4&quot;&gt;bool&lt;/span&gt; enabled&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;!&lt;/span&gt;enabled&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw2&quot;&gt;try&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    f&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;kw2&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Exception1 &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// bla bla&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;kw2&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Exception2 &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// bla bla&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; Example
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; f1&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt; str&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; l &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; str&lt;span class=&quot;sy2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;?&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    errHandler&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;l, enabled_&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; f2&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt; str&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; l &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; str&lt;span class=&quot;sy2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;!&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    errHandler&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;l, enabled_&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;bool&lt;/span&gt; enabled_ &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;2012.12.11 - lambdas vs. variadic templates&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;lambdas_vs_variadic_templates&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-978&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;problem&quot;&gt;problem&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
it worked like a charm for all of the cases, except for one – the call with the &lt;a href=&quot;https://en.wikipedia.org/wiki/variadic templates&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/variadic templates&quot;&gt;variadic templates&lt;/a&gt;. in GCC 4.5 nor 4.7 variadic template parameters cannot be unpacked within the lambda body. namely this &lt;a href=&quot;https://baszerr.eu/lib/exe/fetch.php?media=blog:2012:12:11:lambda_vs_vartempl.cpp&quot; class=&quot;media mediafile mf_cpp&quot; title=&quot;blog:2012:12:11:lambda_vs_vartempl.cpp (284 B)&quot;&gt;example code&lt;/a&gt; does not compile, while it should:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;typename&lt;/span&gt; ...&lt;span class=&quot;me1&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; g&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;A...&lt;span class=&quot;me1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw3&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;kw3&quot;&gt;sizeof&lt;/span&gt;...&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;A&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;typename&lt;/span&gt; ...&lt;span class=&quot;me1&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; f&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;A...&lt;span class=&quot;me1&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; l &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; g&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;a...&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// (clan)g++ Oops... :/&lt;/span&gt;
  l&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;problem&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;problem&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;979-1509&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;compilers&quot;&gt;compilers&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
gcc 4.7 produces following error message on that:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;lambda_vs_vartempl.cpp: In lambda function:
lambda_vs_vartempl.cpp:13:19: error: parameter packs not expanded with ‘...’:
lambda_vs_vartempl.cpp:13:19: note:         ‘a’
lambda_vs_vartempl.cpp:13:20: error: expansion pattern ‘a’ contains no argument packs
lambda_vs_vartempl.cpp: In instantiation of ‘void f(A ...) [with A = {double, double, int}]’:
lambda_vs_vartempl.cpp:19:20:   required from here
lambda_vs_vartempl.cpp:13:26: error: using invalid field ‘f(A ...)::&amp;lt;lambda()&amp;gt;::__a’
lambda_vs_vartempl.cpp:13:26: error: unable to deduce ‘auto’ from ‘&amp;lt;expression error&amp;gt;’&lt;/pre&gt;

&lt;p&gt;
but wait - there&amp;#039;s more! clang++ 3.0-6 outputs this:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;0  libLLVM-3.0.so.1 0x00007f92a16984bf
1  libLLVM-3.0.so.1 0x00007f92a1698909
2  libpthread.so.0  0x00007f92a0618030
3  clang            0x0000000000a3083d clang::Sema::DeduceAutoType(clang::TypeSourceInfo*, clang::Expr*, clang::TypeSourceInfo*&amp;amp;) + 29
4  clang            0x00000000008b001d clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool, bool) + 1533
5  clang            0x00000000008042ee clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&amp;amp;, clang::Parser::ParsedTemplateInfo const&amp;amp;) + 1790
// ...
21 clang            0x00000000005c121f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;amp;) + 319
22 clang            0x00000000005a9a8a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1114
23 clang            0x00000000005a17a4 cc1_main(char const**, char const**, char const*, void*) + 804
24 clang            0x00000000005a0154 main + 596
25 libc.so.6        0x00007f929f6edead __libc_start_main + 253
26 clang            0x00000000005a1329
Stack dump:
// ...
1.      lambda_vs_vartempl.cpp:13:27: current parser token &amp;#039;;&amp;#039;
2.      lambda_vs_vartempl.cpp:12:1: parsing function body &amp;#039;f&amp;#039;
3.      lambda_vs_vartempl.cpp:12:1: in compound statement (&amp;#039;{}&amp;#039;)
clang: error: unable to execute command: Segmentation fault
clang: error: clang frontend command failed due to signal 2 (use -v to see invocation)
clang: note: diagnostic msg: Please submit a bug report to http://llvm.org/bugs/ and include command line arguments and all diagnostic information.
clang: note: diagnostic msg: Preprocessed source(s) are located at:
clang: note: diagnostic msg: /tmp/lambda_vs_vartempl-XSkQV6.ii&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;compilers&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;compilers&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1510-3954&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;final_remarks&quot;&gt;final remarks&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
the good news, that lambda vs. variadic templates bugs are already reported &lt;a href=&quot;http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47226&quot; class=&quot;urlextern&quot; title=&quot;http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47226&quot; rel=&quot;ugc nofollow&quot;&gt;1&lt;/a&gt; &lt;a href=&quot;http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41933&quot; class=&quot;urlextern&quot; title=&quot;http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41933&quot; rel=&quot;ugc nofollow&quot;&gt;2&lt;/a&gt;. the bad news is both are already at least 2 years old… &lt;a href=&quot;http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47226#c2&quot; class=&quot;urlextern&quot; title=&quot;http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47226#c2&quot; rel=&quot;ugc nofollow&quot;&gt;gcc 4.8 is said not to fix this&lt;/a&gt; as well. &lt;a href=&quot;https://en.wikipedia.org/wiki/C++11&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/C++11&quot;&gt;C++11&lt;/a&gt; is complex, after all… ;)
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;final remarks&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;final_remarks&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;3955-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:09:16 +0000</pubDate>
        </item>
    </channel>
</rss>
