dimanche 30 août 2015

invalid use of incomplete type boost function_traits

I tried to make following things work but it failed to compile.

// T is a function with a callback, std::function<void(std::function<void (DataType)> >
struct doFunc {
    template<typename T>
    void operator()(T && func) {
        auto callback = [](typename function_traits<typename function_traits<T>::arg1_type >::arg1_type r) {
            std::cout << r;
        };
        func(callback);
    }
};

// usage
doFunc()([](std::function<void(string)> cb){
    cb("hello");
});

the error is:

invalid use of incomplete type 'struct boost::detail::function_traits_helper<SomeClass::TestBody()::<lambda(std::function<void(std::__cxx11::basic_string<char>)>)>*>'

Is this because the compiler cannot deduct the type out? If I want to keep the usage like that, How to fix it?

Aucun commentaire:

Enregistrer un commentaire