boost::bind와 boost::ref 코드

void
Routing_Table::fill_destination_handle_set (std::set<ACE_HANDLE>& handles, const std::string& driver_name) const
{
    DRIVER_MAP::const_iterator it = drivers_.find (driver_name);
    if (it != drivers_.end ())
    {
        handles.insert (it->second);
    }
}

std::set<ACE_HANDLE>
Routing_Table::find_routes(const Routing_Key& key) const
{
    typedef ROUTING_MAP::const_iterator Iterator;
    std::set<ACE_HANDLE> handles;

    std::pair<Iterator, Iterator> range = routes_.equal_range(key);
    std::for_each (range.first, range.second,
        boost::bind(&Routing_Table::fill_destination_handle_set, this, boost::ref(handles),
            boost::bind(&ROUTING_MAP::value_type::second, _1)));

    return handles;
}

30분 넘게 지대로 고민했다-_-
디버그 걸어봤는데 분명 handles 상태가 제대로 바뀌었다가도 bind를 나가면 초기 상태인 것이 아닌가.

멤버 변수로 해봤더니 이건 멀쩡하게 잘 되고;
한참 고민하다가 책을 펴서 뒤졌고;
봤더니 로컬 변수를 레퍼런스로 넘기고 싶으면 boost::ref를 쓰라는 것이었다.
(const reference는 boost::cref)

ㅠㅠ
책 좀 제대로 읽어 양 선생

트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://www.xeraph.com/tb/2336339 [도움말]

덧글

댓글 입력 영역