std::exception_ptr m_exc; #ifdef _MSC_VER
FuncT m_func; // "const" and std::bind() results in Error C3848 expression would lose const-volatile qualifiers #else
FuncT const m_func; #endif // using std::optional here omits the need that ResultT is default // constructable:
::std::optional<ResultT> m_result;
};
template <typename FuncT> class GenericSolarThreadExecutor<FuncT, void> final : public SolarThreadExecutor
{ public: staticvoid exec( FuncT const& func )
{ typedef GenericSolarThreadExecutor<FuncT, void> ExecutorT;
::std::unique_ptr<ExecutorT> const pExecutor( new ExecutorT(func) );
pExecutor->execute(); if (pExecutor->m_exc)
std::rethrow_exception(pExecutor->m_exc);
}
/** This function will execute the passed functor synchronously in the solarthread,thusthecallingthreadwill(eventually)beblockeduntil thefunctorhasbeencalled. Anyexceptionthatcameupcallingthefunctorinthesolarthread willbecaughtandrethrowninthecallingthread. Theresulttypeofthisfunctionneedstobedefaultconstructable. Pleasekeepinmindnottopassaddressestostackvariables (e.g.foroutparameters)toforeignthreads,useinout_by_ref() forthispurpose.Forinparameters,thismaynotaffectyou,because thefunctorobjectiscopyconstructedintofreestore.Thisway youmustnotuse\verbatimstd::cref()/std::ref()\endverbatimorsimilar forobjectsonyourthread'sstack. Useinout_by_ref()orinout_by_ptr()forthispurpose,e.g.
\code{.cpp} usingnamespacevcl::solarthread;
longn=3; // calling foo( long & r ): syncExecute(std::bind(&foo,inout_by_ref(n))); // calling foo( long * p ): syncExecute(std::bind(&foo,inout_by_ptr(&n)));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.