本文整理汇总了C++中std::deque::emplace_back方法的典型用法代码示例。如果您正苦于以下问题:C++ deque::emplace_back方法的具体用法?C++ deque::emplace_back怎么用?C++ deque::emplace_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::deque
的用法示例。
在下文中一共展示了deque::emplace_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reserve_read
/** Reserve some part of the pipe for reading
\param[in] s is the number of element to reserve
\param[out] rid is an iterator to a description of the
reservation that has been done if successful
\param[in] blocking specify if the call wait for the operation
to succeed
\return true if the reservation was successful
*/
bool reserve_read(std::size_t s,
rid_iterator &rid,
bool blocking = false) {
// Lock the pipe to avoid being disturbed
std::unique_lock<std::mutex> ul { cb_mutex };
TRISYCL_DUMP_T("Before read reservation cb.size() = " << cb.size()
<< " size() = " << size());
if (s == 0)
// Empty reservation requested, so nothing to do
return false;
if (blocking)
/* If in blocking mode, wait for enough elements to read in the
pipe for the reservation. This condition can change when a
write is done */
write_done.wait(ul, [&] { return s <= size(); });
else if (s > size())
// Not enough elements to read in the pipe for the reservation
return false;
// Compute the location of the first element of the reservation
auto first = cb.begin() + read_reserved_frozen;
// Increment the number of frozen elements
read_reserved_frozen += s;
/* Add a description of the reservation at the end of the
reservation queue */
r_rid_q.emplace_back(first, s);
// Return the iterator to the last reservation descriptor
rid = r_rid_q.end() - 1;
TRISYCL_DUMP_T("After reservation cb.size() = " << cb.size()
<< " size() = " << size());
return true;
}
示例2: Enter
void Enter(Activity *activity) {
if (current) {
stack.emplace_back(current);
}
current = activity;
current->dispatchStart();
}
示例3:
S4() {
for(int i = 0; i < 6; ++i) {
m_s1.emplace_back();
m_s2.emplace_back();
m_s3.emplace_back();
}
}
示例4: disambiguate
static inline void propagate_age_update(Cfg& conf, std::deque<Cfg>& tmpres, std::size_t dst) {
// here we propagate an age field update to all pointers that are equal
// and thus experience the update too => only for age updates of next fields
// split to find truly equal pointers
auto shape_split = disambiguate(*conf.shape, dst);
for (Shape* s : shape_split) {
tmpres.emplace_back(Cfg(conf, s));
Cfg& config = tmpres.back();
// pointer equal to dst => experiences age update too
for (std::size_t i = 0; i < s->size(); i++) {
if (i == dst) continue;
if (s->test(i, dst, EQ)) {
#if CAS_OVERAPPROXIMATE_AGE_PROPAGATION
// overapproximation: drop age relation of pointers that observe the age assignemnt
for (std::size_t j = 0; j < s->size(); j++)
for (bool b : {false, true})
config.ages->set(j, b, i, true, AgeRel::BOT);
#else
mk_next_age_equal(config, i, dst, true);
#endif
}
}
}
// the shape/ages from conf may no longer be valid => overwrite the shape/ages
conf.shape = std::move(tmpres.back().shape);
conf.ages = std::move(tmpres.back().ages);
tmpres.pop_back();
}
示例5: Next
int Cursor::Next(const size_t count, std::deque<nx::String>& buf)
{
int rs = 0;
if (isShared())
{
if (extra_state_ && extra_state_->IsReady())
{ // +extra with mixing
std::string rs = extra_state_->Get(extra_delim_);
buf.emplace_back(rs.begin(), rs.end());
++(*extra_state_);
rs = 1;
}
else
{
std::deque<nx::String> tmpbuf;
rs = do_next(count * shared_total_, tmpbuf);
if(rs >= 0)
for(size_t i = 0, j = shared_curr_ - 1; i < count && j < tmpbuf.size();
++i, j = shared_curr_ - 1 + shared_total_*i )
{
buf.push_back(tmpbuf[j]);
}
}
}
else
{
++(*extra_state_);
rs = do_next(count, buf);
}
return rs;
}
示例6: createPlugins
void createPlugins(MyPluginFactory& factory, const std::vector<std::string>& availablePlugins, std::deque<MyPlugin>& plugins)
{
for(const auto& pluginName : availablePlugins)
{
plugins.emplace_back(factory.instance(pluginName));
}
}
示例7: run_on_main_thread
void run_on_main_thread(std::function<void()> &func) {
{
std::unique_lock<std::mutex> lock(main_thread_mutex);
main_func.emplace_back(func);
}
main_thread_cv.notify_all();
std::unique_lock<std::mutex> lock(main_thread_mutex);
main_thread_cv.wait(lock, []{ return main_done || main_func.empty(); });
}
示例8: Enqueue
/** Enqueue a work item */
bool Enqueue(WorkItem* item)
{
boost::unique_lock<boost::mutex> lock(cs);
if (queue.size() >= maxDepth) {
return false;
}
queue.emplace_back(std::unique_ptr<WorkItem>(item));
cond.notify_one();
return true;
}
示例9: element_is_ready
void element_is_ready() {
std::unique_lock<std::mutex> guard(m_lock);
m_elements.emplace_back(std::move(m_current));
m_current.reset(new element);
if (m_elements.size() > m_pool.size() * 2) {
m_parser_wait.wait(guard, [&] {return m_elements.size() < m_pool.size();});
}
guard.unlock();
m_pool_wait.notify_one();
}
示例10: addAndSetTime
// ------------------------------------------------------------------------
void addAndSetTime(uint32_t ping, uint64_t server_time)
{
if (m_synchronised.load() == true)
return;
if (m_force_set_timer.load() == true)
{
m_force_set_timer.store(false);
m_synchronised.store(true);
STKHost::get()->setNetworkTimer(server_time + (uint64_t)(ping / 2));
return;
}
const uint64_t cur_time = StkTime::getMonoTimeMs();
// Discard too close time compared to last ping
// (due to resend when packet loss)
// 10 packets per second as seen in STKHost
const uint64_t frequency = (uint64_t)((1.0f / 10.0f) * 1000.0f) / 2;
if (!m_times.empty() &&
cur_time - std::get<2>(m_times.back()) < frequency)
return;
// Take max 20 averaged samples from m_times, the next addAndGetTime
// is used to determine that server_time if it's correct, if not
// clear half in m_times until it's correct
if (m_times.size() >= 20)
{
uint64_t sum = std::accumulate(m_times.begin(), m_times.end(),
(uint64_t)0, [cur_time](const uint64_t previous,
const std::tuple<uint32_t, uint64_t, uint64_t>& b)->uint64_t
{
return previous + (uint64_t)(std::get<0>(b) / 2) +
std::get<1>(b) + cur_time - std::get<2>(b);
});
const int64_t averaged_time = sum / 20;
const int64_t server_time_now = server_time + (uint64_t)(ping / 2);
int difference = (int)std::abs(averaged_time - server_time_now);
if (std::abs(averaged_time - server_time_now) <
UserConfigParams::m_timer_sync_difference_tolerance)
{
STKHost::get()->setNetworkTimer(averaged_time);
m_times.clear();
m_force_set_timer.store(false);
m_synchronised.store(true);
Log::info("NetworkTimerSynchronizer", "Network "
"timer synchronized, difference: %dms", difference);
return;
}
m_times.erase(m_times.begin(), m_times.begin() + 10);
}
m_times.emplace_back(ping, server_time, cur_time);
}
示例11: append
void
append(Args&&... args) {
static_assert(
std::is_same<typename Event::tag, Tag>::value,
"message protocol is not compatible with this message queue"
);
if(!upstream_) {
return operations.emplace_back(aux::make_frozen<Event>(std::forward<Args>(args)...));
}
upstream_->send<Event>(std::forward<Args>(args)...);
}
示例12: DbgTimingInfo
void ProfileDrawer::DbgTimingInfo(DbgTimingInfoType type, const spring_time start, const spring_time end)
{
if (!IsEnabled())
return;
switch (type) {
case TIMING_VIDEO: {
vidFrames.emplace_back(start, end);
} break;
case TIMING_SIM: {
simFrames.emplace_back(start, end);
} break;
case TIMING_GC: {
lgcFrames.emplace_back(start, end);
} break;
case TIMING_SWAP: {
swpFrames.emplace_back(start, end);
} break;
case TIMING_UNSYNCED: {
uusFrames.emplace_back(start, end);
} break;
}
}
示例13: dispatcher_
result_type
traverse(std::conditional_t< reassmble, ast::expression &&, ast::expression const & > _input)
{ // if reassmble is true, then input is taken apart, then reassembled
assert(output_.empty());
if (_input.rest_.empty()) {
return dispatcher_(std::move(_input.first_));
} else if (_input.rest_.size() == 1) {
auto & operation_ = _input.rest_.back();
return dispatcher_(std::move(_input.first_),
operation_.operator_,
std::move(operation_.operand_));
} else {
//output_.reserve(_input.rest_.size() * 2 + 1); // total number of operators and operands
std::stack< aggregate_wrapper< lhs_op > > lhs_op_;
for (auto & operation_ : _input.rest_) {
size_type const precedence_ = ast::precedence(operation_.operator_);
while (!lhs_op_.empty()) {
lhs_op const & top_ = lhs_op_.top();
if (ast::precedence(top_.operator_) < precedence_) {
break;
}
output_.emplace_back(top_.lhs_, top_.operator_, output_.size());
lhs_op_.pop();
}
lhs_op_.emplace(output_.size(), operation_.operator_);
output_.emplace_back(&operation_.operand_);
}
while (!lhs_op_.empty()) {
lhs_op const & top_ = lhs_op_.top();
output_.emplace_back(top_.lhs_, top_.operator_, output_.size());
lhs_op_.pop();
}
output_.emplace_front(&_input.first_);
return operator () (output_.back());
}
}
示例14: getCachedFile
std::unique_ptr<ui8[]> getCachedFile(ResourceID rid)
{
for(auto & file : cache)
{
if (file.name == rid)
return file.getCopy();
}
// Still here? Cache miss
if (cache.size() > cacheSize)
cache.pop_front();
auto data = CResourceHandler::get()->load(rid)->readAll();
cache.emplace_back(std::move(rid), data.second, std::move(data.first));
return cache.back().getCopy();
}
示例15: addComponent
ComponentType& addComponent(Args&&... args)
{
static_assert(std::is_base_of<NodeComponent, ComponentType>::value,
"ComponentType must inherit from NodeComponent.");
assert(!hasComponent<ComponentType>() &&
"SceneNode::addComponent component of that type already exists.");
ComponentType* component{
new ComponentType{std::forward<Args>(args)...}};
component->parent = this;
components.emplace_back(std::unique_ptr<NodeComponent>{component});
componentArray[getComponentTypeId<ComponentType>()] = component;
componentBitset[getComponentTypeId<ComponentType>()] = true;
return *component;
}