Skip to content

Instantly share code, notes, and snippets.

@bzar
Last active August 29, 2015 14:12
Show Gist options
  • Save bzar/85e8dd82c93bad67391e to your computer and use it in GitHub Desktop.
Save bzar/85e8dd82c93bad67391e to your computer and use it in GitHub Desktop.
#include <iostream>
#include <functional>
#include <vector>
using Cb = std::function<void()>;
using Cbs = std::vector<Cb>;
void print(Cbs& cbs)
{
auto n = cbs.size();
for(decltype(n) i = 0; i < n; ++i)
{
cbs.at(i)();
}
std::cout << std::endl;
}
int main()
{
Cbs fs;
fs.reserve(4); // Issue shows after this is exceeded
int i = 42;
fs.push_back([i, &fs]() {
fs.push_back([i]() {
std::cout << "x " << i << std::endl;
});
std::cout << i << std::endl;
});
print(fs);
print(fs);
print(fs);
print(fs);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment