templates - Visual C++ 2015 std::function vs C2893 -


so experimenting std::function , templates , came code below. unfortunately turns out cause c2893 on visual studio 2015 (maybe works fine on other compilers?). not know whether helps when replace first parameter of nexthandler void* compilation error goes away...

#include <functional>  template<typename t> class block { public:      typedef block currentblock;     typedef t nextblock;      typedef std::function<void (currentblock& currentblock,         nextblock& nextblock)>         nexthandler;  private:      nextblock*  _nextblock;     nexthandler _nexthandler;  protected:      virtual void     doprocess() = 0;  public:      nextblock&     next(nextblock& nextblock, nexthandler handler)     {         _nextblock = &nextblock;         _nexthandler = handler;         return nextblock;     }      void     process()     {         doprocess();         _nexthandler(*this, *_nextblock);         _nextblock->process();     } };  template<> class block<void> { protected:      virtual void     doprocess() = 0;  public:      void     process()     {         doprocess();     } };  class mockblock1 : public block<void> { public:      void     doprocess() override     {     } };  class mockblock0 : public block<mockblock1> { public:      void     doprocess() override     {     } };  void somefunction() {     mockblock0 b0;     mockblock1 b1;      b0.next(b1, [](mockblock0& b0, mockblock1& b1)         {         }); } 

full error message is:

c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1494): error c2893: failed specialize function template 'unknown-type std::invoke(_callable &&,_types &&...)' c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1494): note: following template arguments: c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1494): note: '_callable=_decayed &' c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1494): note: '_types={block<mockblock1> &, mockblock1 &}' c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(210): note: see reference function template instantiation 'void std::_invoke_ret<_rx,_callable&,block<mockblock1>&,mockblock1&>(std::_forced<_rx,true>,_callable &,block<mockblock1> &,mockblock1 &)' being compiled                 [             _rx=void,             _callable=_decayed         ] c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(208): note: while compiling class template member function 'void std::_func_impl<_decayed,_alloc,_ret,block<mockblock1> &,mockblock1 &>::_do_call(block<mockblock1> &,mockblock1 &)'                 [             _alloc=std::allocator<int>,             _ret=void         ] c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(136): note: see reference class template instantiation 'std::_func_impl<_decayed,_alloc,_ret,block<mockblock1> &,mockblock1 &>' being compiled                 [             _alloc=std::allocator<int>,             _ret=void         ] c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(339): note: see reference class template instantiation 'std::_is_large<_myimpl>' being compiled c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(318): note: see reference function template instantiation 'void std::_func_class<_ret,block<mockblock1> &,mockblock1 &>::_reset_alloc<_ty,std::allocator<int>>(_fx &&,const _alloc &)' being compiled                 [             _ret=void,             _ty=somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>,             _fx=somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>,             _alloc=std::allocator<int>         ] c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(318): note: see reference function template instantiation 'void std::_func_class<_ret,block<mockblock1> &,mockblock1 &>::_reset_alloc<_ty,std::allocator<int>>(_fx &&,const _alloc &)' being compiled                 [             _ret=void,             _ty=somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>,             _fx=somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>,             _alloc=std::allocator<int>         ] c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(484): note: see reference function template instantiation 'void std::_func_class<_ret,block<mockblock1> &,mockblock1 &>::_reset<somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>>(_fx &&)' being compiled                 [             _ret=void,             _fx=somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>         ] c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(484): note: see reference function template instantiation 'void std::_func_class<_ret,block<mockblock1> &,mockblock1 &>::_reset<somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>>(_fx &&)' being compiled                 [             _ret=void,             _fx=somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>         ] c:\test\blocks.cpp(88): note: see reference function template instantiation 'std::function<void (block<mockblock1> &,mockblock1 &)>::function<somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>>(_fx)' being compiled                 [             _fx=somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>         ] c:\test\blocks.cpp(88): note: see reference function template instantiation 'std::function<void (block<mockblock1> &,mockblock1 &)>::function<somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>>(_fx)' being compiled                 [             _fx=somefunction::<lambda_3b7d9d95683ccbaabd52b19687773e09>         ] 

what's mockblock0::nexthandler aka block<mockblock1>::nexthandler?

it's std::function<void (block<mockblock1>&, mockblock1&)>.

can [](mockblock0& b0, mockblock1& b1) { /* stuff */ } called lvalue of type block<mockblock1>? can't, because not block<mockblock1>s mockblock0s.

hence error.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -