Last active
August 29, 2015 14:12
-
-
Save bzar/85e8dd82c93bad67391e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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