liwenxiong0721 2023-10-16 23:21 采纳率: 33.3%
浏览 5

boost库future then问题


   boost::shared_future<boost::shared_ptr<adam::firmware::ImageData> > get_image(adam::firmware::CameraEnums::CameraImageType type)
    {
        return enqueue(type);
        
    }
#pragma once

#include <boost/thread/future.hpp>
#include <boost/statechart/asynchronous_state_machine.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

namespace adam
{
    namespace firmware
    {
        namespace states
        {
/**
 * The InStateHandler allows a callback to be guarded based on the current state machine state. Use this in combination
 * with the adam::infra::SchedulerExecutor to call the callback on the state machine's thread, to avoid race conditions.
 *
 * This handler defines an `operator()` method taking a boost::shared_future<TFutureResult> as parameter. The callback
 * method must have the same signature. Passing a callback returning a non-void value is currently not supported.
 *
 * @tparam TState The state type that should be active when the callback is executed.
 * @tparam TFutureResult The result of the future this continuation is used for.
 */
template<typename TState, typename TFutureResult>
struct InStateHandler
{
    // result struct required to allow boost::result_of<>
    template<typename> struct result;

    template<typename F, typename T>
    struct result<F(T)>
    {
        typedef void type;
    };

    /**
     * Constructor.
     *
     * @param[in] machine The state machine to check. Typically, from within a state `&outermost_context()` is used.
     * @param[in] callback The callback to call if the state machine is in the @c TState state when this handler is executed.
     */
    InStateHandler(typename TState::outermost_context_type* machine, boost::function<void(boost::shared_future<TFutureResult>&)> callback)
        : m_machine(machine)
        , m_callback(callback)
    {
    }

    void operator()(boost::shared_future<TFutureResult>& future)
    {
        if (m_machine->template state_cast<const TState*>() != NULL)
        {
            m_callback(future);
        }
    }

private:
    typename TState::outermost_context_type* m_machine;
    boost::function<void(boost::shared_future<TFutureResult>&)> m_callback;
};
void Preparing::schedule_exposure_check()
{
    // First stabilize exposure
    
    outermost_context().components.camera_component->get_image(CameraEnums::NextImage)
        .then(outermost_context().continuation_executor,
            InStateHandler<Preparing, boost::shared_ptr<adam::firmware::ImageData> >(
                &outermost_context(),
                boost::bind(
                    &Preparing::check_exposure_stability,
                    this,
                    _1)));
                    
    
    
}
/home/lwx/firm161/application/control/states/preparing.cpp: In member function ‘void adam::firmware::states::Preparing::schedule_exposure_check()’:
/home/lwx/firm161/application/control/states/preparing.cpp:58:25: error: no matching function for call to ‘boost::shared_future<boost::shared_ptr<adam::firmware::ImageData> >::then(adam::infra::SchedulerExecutor<>&, adam::firmware::states::InStateHandler<adam::firmware::states::Preparing, boost::shared_ptr<adam::firmware::ImageData> >)’
                     _1)));
                         ^
In file included from /usr/local/include/boost/thread.hpp:24:0,
                 from /home/lwx/firm161/hal/../infra/worker_service.h:9,
                 from /home/lwx/firm161/hal/../vision/tracking/template_scoring.h:5,
                 from /home/lwx/firm161/hal/../vision/tracking/position_enumeration.h:5,
                 from /home/lwx/firm161/hal/../vision/tracking/door_tracker.h:3,
                 from /home/lwx/firm161/hal/../application/image_data.h:20,
                 from /home/lwx/firm161/application/control/states/preparing.h:5,
                 from /home/lwx/firm161/application/control/states/preparing.cpp:2:
/usr/local/include/boost/thread/future.hpp:2130:9: note: candidate: template<class F> boost::future<typename boost::result_of<F(boost::shared_future<R>)>::type> boost::shared_future<R>::then(F&&) const [with F = F; R = boost::shared_ptr<adam::firmware::ImageData>]
         then(BOOST_THREAD_FWD_REF(F) func) const; // EXTENSION
         ^
/usr/local/include/boost/thread/future.hpp:2130:9: note:   template argument deduction/substitution failed:
/home/lwx/firm161/application/control/states/preparing.cpp:58:25: note:   candidate expects 1 argument, 2 provided
                     _1)));
                         ^
In file included from /usr/local/include/boost/thread.hpp:24:0,
                 from /home/lwx/firm161/hal/../infra/worker_service.h:9,
                 from /home/lwx/firm161/hal/../vision/tracking/template_scoring.h:5,
                 from /home/lwx/firm161/hal/../vision/tracking/position_enumeration.h:5,
                 from /home/lwx/firm161/hal/../vision/tracking/door_tracker.h:3,
                 from /home/lwx/firm161/hal/../application/image_data.h:20,
                 from /home/lwx/firm161/application/control/states/preparing.h:5,
                 from /home/lwx/firm161/application/control/states/preparing.cpp:2:
/usr/local/include/boost/thread/future.hpp:2133:9: note: candidate: template<class F> boost::future<typename boost::result_of<F(boost::shared_future<R>)>::type> boost::shared_future<R>::then(boost::launch, F&&) const [with F = F; R = boost::shared_ptr<adam::firmware::ImageData>]
         then(launch policy, BOOST_THREAD_FWD_REF(F) func) const; // EXTENSION
         ^
/usr/local/include/boost/thread/future.hpp:2133:9: note:   template argument deduction/substitution failed:
/home/lwx/firm161/application/control/states/preparing.cpp:52:35: note:   cannot convert ‘((adam::firmware::states::Preparing*)this)->adam::firmware::states::Preparing::<anonymous>.boost::statechart::state<adam::firmware::states::Preparing, adam::firmware::states::Viewing>::<anonymous>.boost::statechart::simple_state<MostDerived, Context, InnerInitial, historyMode>::outermost_context<adam::firmware::states::Preparing, adam::firmware::states::Viewing, boost::mpl::list<mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, (boost::statechart::history_mode)0u>().adam::firmware::StateMachine::continuation_executor’ (type ‘adam::infra::SchedulerExecutor<>’) to type ‘boost::launch’
         .then(outermost_context().continuation_executor,
                                   ^
In file included from /usr/local/include/boost/thread.hpp:24:0,
                 from /home/lwx/firm161/hal/../infra/worker_service.h:9,
                 from /home/lwx/firm161/hal/../vision/tracking/template_scoring.h:5,
                 from /home/lwx/firm161/hal/../vision/tracking/position_enumeration.h:5,
                 from /home/lwx/firm161/hal/../vision/tracking/door_tracker.h:3,
                 from /home/lwx/firm161/hal/../application/image_data.h:20,
                 from /home/lwx/firm161/application/control/states/preparing.h:5,
                 from /home/lwx/firm161/application/control/states/preparing.cpp:2:
/usr/local/include/boost/thread/future.hpp:2137:9: note: candidate: template<class Ex, class F> boost::future<typename boost::result_of<F(boost::shared_future<R>)>::type> boost::shared_future<R>::then(Ex&, F&&) const [with Ex = Ex; F = F; R = boost::shared_ptr<adam::firmware::ImageData>]
         then(Ex& ex, BOOST_THREAD_FWD_REF(F) func) const; // EXTENSION
         ^
/usr/local/include/boost/thread/future.hpp:2137:9: note:   template argument deduction/substitution failed:
/usr/local/include/boost/thread/future.hpp: In substitution of ‘template<class Ex, class F> boost::future<typename boost::result_of<F(boost::shared_future<R>)>::type> boost::shared_future<R>::then(Ex&, F&&) const [with Ex = adam::infra::SchedulerExecutor<>; F = adam::firmware::states::InStateHandler<adam::firmware::states::Preparing, boost::shared_ptr<adam::firmware::ImageData> >]’:
/home/lwx/firm161/application/control/states/preparing.cpp:58:25:   required from here
/usr/local/include/boost/thread/future.hpp:5059:3: error: no type named ‘type’ in ‘struct boost::result_of<adam::firmware::states::InStateHandler<adam::firmware::states::Preparing, boost::shared_ptr<adam::firmware::ImageData> >(boost::shared_future<boost::shared_ptr<adam::firmware::ImageData> >)>’
   shared_future<R>::then(Ex& ex, BOOST_THREAD_FWD_REF(F) func)  const
   ^
/home/lwx/firm161/application/control/states/preparing.cpp: In member function ‘void adam::firmware::states::Preparing::check_exposure_stability(boost::shared_future<boost::shared_ptr<adam::firmware::ImageData> >)’:
问题:
在boost1.61.0+opencv3.1.0编译正常,在boost1.61+opencv4.6.0编译报如上错误,请问怎么解决future then问题,谢谢
  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-10-17 08:43
    关注

    【以下回答由 GPT 生成】

    问题描述得相对清晰,但可能对于非技术人员来说还有一些陌生的术语,例如boost库和future then等。为了让ChatGPT更好地理解你的问题,你可以提供更多上下文信息,例如这段代码的作用和期望的结果是什么,以及你遇到的具体问题是什么。或者,你可以尝试简化问题并提供更具体的例子来说明问题。这样可以帮助ChatGPT更好地理解你的问题并提供准确的解决方案。


    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 10月16日

悬赏问题

  • ¥15 C++ 句柄后台鼠标拖动如何实现
  • ¥15 有人会SIRIUS 5.8.0这个软件吗
  • ¥30 comsol仿真等离激元
  • ¥15 静电纺丝煅烧后如何得到柔性纤维
  • ¥15 (标签-react native|关键词-镜像源)
  • ¥100 照片生成3D人脸视频
  • ¥15 伪装视频时长问题修改MP4的时长问题,
  • ¥15 JETSON NANO
  • ¥15 VS开发qt时如何在paintgl函数中用pushbutton控制切换纹理
  • ¥20 关于 openpyxl 处理excel文件地问题