2017-01-22 8 views
2

나는 이미 여기에 이미 답변 된 질문을 찾을 수 없었을 것입니다. 누군가가 성공적으로 람다없이 coroutine2 lib를 사용하면 도움이 될 것입니다. sumarized 내 문제 :람다없이 부스트 coroutine2 사용

class worker { 
... 
void import_data(boost::coroutines2::coroutine 
<boost::variant<long, long long, double, std::string> >::push_type& sink) { 
... 
sink(stol(fieldbuffer)); 
... 
sink(stod(fieldbuffer)); 
... 
sink(fieldbuffer); //Fieldbuffer is a std::string 
} 
}; 

나는 그 자리에 각 산출 값을 넣는 작업을 가진 다른 클래스 내부에서 코 루틴,로 사용하려는, 그래서 객체 인스턴스화하려고 :

worker _data_loader; 
boost::coroutines2::coroutine<boost::variant<long, long long, double, string>>::pull_type _fieldloader 
     (boost::bind(&worker::import_data, &_data_loader)); 

하지만 실 거예요 컴파일 :

/usr/include/boost/bind/mem_fn.hpp:342:23: 
error: invalid use of non-static member function of type 
‘void (worker::)(boost::coroutines2::detail::push_coroutine<boost::variant<long int, long long int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)’ 

누군가는이 문제에 어떤 도움이 되거 수 있을까요?

답변

1

이것은 부스트 ​​코 루틴과 아무 관련이 없습니다.

멤버 함수와 바인딩하는 것입니다. 당신은 언 바운드 매개 변수를 노출하는 것을 잊었다 :

boost::bind(&worker::import_data, &_data_loader, _1) 

Live On Coliru

#include <boost/coroutine2/all.hpp> 
#include <boost/variant.hpp> 
#include <boost/bind.hpp> 
#include <string> 

using V = boost::variant<long, long long, double, std::string>; 
using Coro = boost::coroutines2::coroutine<V>; 

class worker { 
    public: 
    void import_data(Coro::push_type &sink) { 
     sink(stol(fieldbuffer)); 
     sink(stod(fieldbuffer)); 
     sink(fieldbuffer); // Fieldbuffer is a std::string 
    } 

    std::string fieldbuffer = "+042.42"; 
}; 

#include <iostream> 
int main() 
{ 
    worker _data_loader; 
    Coro::pull_type _fieldloader(boost::bind(&worker::import_data, &_data_loader, _1)); 

    while (_fieldloader) { 
     std::cout << _fieldloader.get() << "\n"; 
     _fieldloader(); 
    } 
} 

인쇄를

42 
42.42 
+042.42