Broken capture() example

Broken capture() example

Beta 5 broke my beta 4 code involving capture of a static member function, so it took a while to tease it out and simplify. Run the following in MSVC Debug or Release modes to obtain different output, this function:

void bar(dense& Out, dense& Arg, usize& Len)
Out = scatter(fill(usize(1), Arg.length()), Arg, Len);

...and this snip:

dense arg = dense::parse("{0, 2}");
dense out;
#ifdef _DEBUG
bar(out, arg, usize(4));
closure&, dense&, usize&)> clo;
if (clo.empty())
clo = capture(bar);
clo(out, arg, usize(4));
cout << "out: ";
const_range r = out.read_only_range();
for (const_range::const_iterator i = r.begin(); i != r.end(); ++i)
cout << *i << " ";
cout << endl;

The output should be "out: 1 0 1 0", which itis for Debug, but for Release it is "out: 0 0 1 0". Also,the problem seems tobe the combination if scatter() and fill() e.g. replacing fill() with a predefined containershows that scatter() is OK on its own and likewise fill() is OK on its own, too.

Best regards,
- paul

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Within minutes of posting (above) the cure presented itself, replacingcode of bar()with:

Out = add_merge(usize(1), Arg, Len);

To pun theold Miller Lite commercial tag line: "Great Taste...Less Filling!" (see:

- paul


I'm investigating the problem and will get back to you soon. Thanks for reporting it.


I was not able to reproduce this problem. I tried various configurations on both Windows and Linux and I always got the expected result: "out: 1 0 1 0".

Would you please let me know how you built your program to get this problem? Especially,

  1. What compiler did you use?
  2. Did you link with arbb_dev lib or arbb lib?
  3. Was ARBB_OPT_LEVEL set? What value?
  4. Was ARBB_EMULATE set?
  5. Did you call set_emulation_mode() in your code?


MSVC++ 2010 in MS Visual Studio
link with arbb_dev.lib for Debug, arbb.lib for Release (is this usual?)
does not call set_emulation_mode()

running on i7-2600 "Sandy Bridge" under Windows 7 Pro 64-bit, Service Pack 1

Leave a Comment

Please sign in to add a comment. Not a member? Join today