boost::bind 사용법 ???
class chat_session
: public chat_participant,
public boost::enable_shared_from_this
{
.....
void deliver(const chat_message& msg)
{
..................
}
}
class chat_room
{
public:
void join(chat_participant_ptr participant)
{
participants_.insert(participant);
std::for_each(recent_msgs_.begin(), recent_msgs_.end(),
boost::bind(&chat_participant::deliver, participant, _1));
}
void deliver(const chat_message& msg)
{
recent_msgs_.push_back(msg);
while (recent_msgs_.size() > max_recent_msgs)
recent_msgs_.pop_front();
std::for_each(participants_.begin(), participants_.end(),
boost::bind(&chat_participant::deliver, _1, boost::ref(msg)));
}
private:
std::set participants_;
enum { max_recent_msgs = 100 };
chat_message_queue recent_msgs_;
};
bind의 일반적인 사용법은
(함수,_1)(인자) 또는 (함수,인자) 이런 방법으로 작성되는데
첫번째 것은 (함수,인자,_1)이고 두번째 것은 (함수,_1,인자)로 작성되어 있어서
잘 이해 하지 못하겠습니다. 고수님들 답변 부탁 드립니다.
댓글 달기