Last active
January 1, 2016 10:29
-
-
Save nekko1119/8132124 to your computer and use it in GitHub Desktop.
boost::signal2でshared_ptrを用いたトラッキングの方法
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> | |
void hello() | |
{ | |
std::cout << "Hello "; | |
} | |
struct World | |
{ | |
void operator()() | |
{ | |
std::cout << "World"; | |
} | |
}; | |
struct CoutChar | |
{ | |
CoutChar(char c) | |
: letter(c) | |
{} | |
void print() | |
{ | |
std::cout << letter; | |
} | |
char letter; | |
}; | |
#include <boost/signals2.hpp> | |
int main() | |
{ | |
World world; | |
CoutChar c('!'); | |
using boost::signals2::signal; | |
signal<void()> s; | |
s.connect(&hello); | |
s.connect(world); | |
s.connect(std::bind(&CoutChar::print, c)); | |
s(); | |
std::cout << std::endl; | |
s.disconnect_all_slots(); | |
s.connect(1, world); | |
s.connect(0, &hello); | |
s.connect(2, std::bind(&CoutChar::print, c)); | |
s(); | |
std::cout << std::endl; | |
s.disconnect_all_slots(); | |
s.connect(1, world); | |
s.connect(0, &hello); | |
{ | |
std::shared_ptr<CoutChar> c(new CoutChar('!')); | |
s.connect(2, signal<void()>::slot_type(&CoutChar::print, c.get()).track_foreign(c)); | |
std::cout << s.num_slots(); | |
std::cout << std::endl; | |
} | |
s(); | |
std::cout << std::endl; | |
std::cout << s.num_slots(); | |
std::cout << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment