Error when compiling using Bosma in VS 2019 16.8.5

  c++, visual-c++, visual-studio

When compiling in Visual Studio Community 2019 16.8.5, with toolset v142, it throws the next error:

1>C:Program Files (x86)Microsoft Visual
Studio19CommunityVCToolsMSVC.28.29333includexmemory(230,12):
error C2664:
‘Bosma::EveryTask::EveryTask(std::chrono::system_clock::duration,std::function<void
(void)> &&,bool)’: cannot convert argument 2 from ‘_Ty’ to
‘std::function<void (void)> &&’ 1> with 1> [ 1>
_Ty=std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const detail_t &,bool),templateData_t &,detail_t &> 1>
] 1>C:Program Files (x86)Microsoft Visual
Studio19CommunityVCToolsMSVC.28.29333includexmemory(228,1):
message : Reason: cannot convert from ‘_Ty’ to ‘std::function<void
(void)>’ 1> with 1> [ 1>
_Ty=std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const detail_t &,bool),templateData_t &,sensorData_t &> 1>
] 1>C:Program Files (x86)Microsoft Visual
Studio19CommunityVCToolsMSVC.28.29333includexmemory(230,33):
message : No user-defined-conversion operator available that can
perform this conversion, or the operator cannot be called
1>Scheduler.h(37,9): message : see declaration of
‘Bosma::EveryTask::EveryTask’ 1>C:Program Files (x86)Microsoft
Visual
Studio19CommunityVCToolsMSVC.28.29333includememory(1563):
message : see reference to function template instantiation ‘void
std::_Construct_in_place<_Ty,const
std::chrono::system_clock::duration&,std::_Binder<std::_Unforced,void
(__cdecl &)(const templateData_t &,const detail_t
&,bool),templateData_t &,detail_t &>>(_Ty &,const
std::chrono::system_clock::duration &,std::_Binder<std::_Unforced,void
(__cdecl &)(const templateData_t &,const detail_t
&,bool),templateData_t &,detail_t &> &&) noexcept(false)’ being
compiled 1> with 1> [ 1> _Ty=Bosma::EveryTask
1> ] 1>C:Program Files (x86)Microsoft Visual
Studio19CommunityVCToolsMSVC.28.29333includememory(2207):
message : see reference to function template instantiation
‘std::_Ref_count_obj2<_Ty>::_Ref_count_obj2<const
std::chrono::system_clock::duration&,std::_Binder<std::_Unforced,void
(__cdecl &)(const templateData_t &,const detail_t
&,bool),templateData_t &,detail_t &>>(const
std::chrono::system_clock::duration &,std::_Binder<std::_Unforced,void
(__cdecl &)(const templateData_t &,const detail_t
&,bool),templateData_t &,detail_t &> &&)’ being compiled 1>
with 1> [ 1> _Ty=Bosma::EveryTask 1> ] 1>C:Program Files (x86)Microsoft Visual
Studio19CommunityVCToolsMSVC.28.29333includememory(2208):
message : see reference to function template instantiation
‘std::_Ref_count_obj2<_Ty>::_Ref_count_obj2<const
std::chrono::system_clock::duration&,std::_Binder<std::_Unforced,void
(__cdecl &)(const templateData_t &,const detail_t
&,bool),templateData_t &,detail_t &>>(const
std::chrono::system_clock::duration &,std::_Binder<std::_Unforced,void
(__cdecl &)(const templateData_t &,const detail_t
&,bool),templateData_t &,detail_t &> &&)’ being compiled 1>
with 1> [ 1> _Ty=Bosma::EveryTask 1> ] 1>External librariesschedulerScheduler.h(132): message : see reference to
function template instantiation ‘std::shared_ptrBosma::EveryTask
std::make_shared<Bosma::EveryTask,const
std::chrono::system_clock::duration&,std::_Binder<std::_Unforced,void
(__cdecl &)(const templateData_t &,const sensorData_t
&,bool),detail_t &,sensorData_t &>>(const
std::chrono::system_clock::duration &,std::_Binder<std::_Unforced,void
(__cdecl &)(const templateData_t &,const detail_t
&,bool),templateData_t &,detail_t &> &&)’ being compiled
1>serviceController.cpp(107):
message : see reference to function template instantiation ‘void
Bosma::Scheduler::every<void(__cdecl &)(const templateData_t &,const
detail_t &,bool),templateData_t&,detail_t &>(const
std::chrono::system_clock::duration,_Callable,templateData_t
&,detail_t &)’ being compiled 1> with 1> [ 1>
_Callable=void (__cdecl &)(const templateData_t &,const detail_t &,bool) 1> ]

As far I can understand, there is a problem with std::move. It was working flawlessly with previous version of VS 🙁

My functions have the following signatures:

void checkA (const templateData_t &templateData, const detail_t &detail, bool force = false);

And I do:

Bosma::Scheduler sched(max_n_threads);
sched.every(std::chrono::seconds(totalSeconds), checkA, templateObject, detail);

Bosma::Scheduler::Every has the following signature:

void every(const Clock::duration time, _Callable &&f, _Args &&... args) {
  std::shared_ptr<Task> t = std::make_shared<EveryTask>
                                (time, std::bind(std::forward<_Callable>(f),
                                                 std::forward<_Args>(args)...));
  auto next_time = t->get_new_time();
  add_task(next_time, std::move(t));
}

And EveryTask:

EveryTask(Clock::duration time, 
          std::function<void()> &&f, 
          bool interval = false) 
          :
          Task(std::move(f), true, interval), time(time) {}

And Task:

explicit Task(std::function<void()> &&f, 
              bool recur = false, 
              bool interval = false) 
              :
              f(std::move(f)), recur(recur), interval(interval) {}

So, I think is something about conversion between lvalues and rvalues.

Thank you very much 🙂

Source: Windows Questions C++

LEAVE A COMMENT