Created
August 13, 2016 06:21
-
-
Save zwpp/e1b7a285af3b13988e920289e1649c0b 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 <algorithm> | |
//#include <array> | |
//#include <vector> | |
class Nyan { | |
public: | |
std::function<void()> fs[2]; | |
void hoge(); | |
void fuga(); | |
void caller(); | |
Nyan(); | |
private: | |
unsigned stat; | |
}; | |
Nyan::Nyan() :stat(0) { | |
auto behaviors = {&Nyan::hoge, &Nyan::fuga}; | |
std::transform(std::begin(behaviors), | |
std::end(behaviors), | |
fs, | |
[this](auto f){ return std::bind(f, this); } | |
); | |
}; | |
void Nyan::hoge() { | |
std::cout << "hoge" << std::endl; | |
stat = 1; | |
} | |
void Nyan::fuga() { | |
std::cout << "fuga" << std::endl; | |
stat = 0; | |
} | |
void Nyan::caller() { | |
fs[stat](); | |
} | |
int main() { | |
Nyan n; | |
n.caller(); | |
n.caller(); | |
n.caller(); | |
n.caller(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment