inline _pDst polymorphic_crosscast(_tSrc* x) { static_assert(is_polymorphic<_tSrc>::value, "Non-polymorphic class found."); static_assert(is_pointer<_pDst>::value, "Non-pointer destination found."); auto p(dynamic_cast<_pDst>(x)); yassume(p); return p; }
inline _pDst polymorphic_downcast(_tSrc* x) { static_assert(is_polymorphic<_tSrc>::value, "Non-polymorphic class found."); static_assert(is_pointer<_pDst>::value, "Non-pointer destination found."); static_assert(is_base_of<_tSrc, remove_cv_t< remove_pointer_t<_pDst>>>::value, "Wrong destination type found."); yassume(dynamic_cast<_pDst>(x) == x); return static_cast<_pDst>(x); }
void Analyze(ValueNode& root, const TokenList& token_list) { #if 0 if(token_list.empty()) throw LoggedEvent("Empty token list found;", Alert); #endif if(Validate(token_list.begin(), token_list.end()) != token_list.end()) throw LoggedEvent("Redundant ')' found.", Alert); const auto res(Reduce(root, token_list.begin(), token_list.end())); yassume(res == token_list.end()); }
thread_pool::thread_pool(size_t n, std::function<void()> on_enter, std::function<void()> on_exit) : workers(n) { for(size_t i = 0; i < n; ++i) workers.emplace_back([=]{ if(on_enter) on_enter(); while(true) { std::unique_lock<std::mutex> lck(queue_mutex); condition.wait(lck, [this]{ return stopped || !tasks.empty(); }); if(tasks.empty()) { // NOTE: Do nothing for spurious wakeup. if(stopped) break; } else { const auto task(std::move(tasks.front())); tasks.pop(); lck.unlock(); try { task(); } catch(std::future_error&) { yassume(false); } } } if(on_exit) on_exit(); }); }