本文整理汇总了C++中stack::emplace方法的典型用法代码示例。如果您正苦于以下问题:C++ stack::emplace方法的具体用法?C++ stack::emplace怎么用?C++ stack::emplace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack
的用法示例。
在下文中一共展示了stack::emplace方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute
void compute(stack<int>& operands, stack<char>& operators) {
const int left = operands.top();
operands.pop();
const int right = operands.top();
operands.pop();
const char op = operators.top();
operators.pop();
if (op == '+') {
operands.emplace(left + right);
} else if (op == '-') {
operands.emplace(left - right);
}
}
示例2: compute
void compute(stack<int>& operands, stack<string>& operators) {
const int left = operands.top();
operands.pop();
const int right = operands.top();
operands.pop();
const string op = operators.top();
operators.pop();
if (op == "+") {
operands.emplace(left + right);
} else if (op == "-") {
operands.emplace(left - right);
} else if (op == "*") {
operands.emplace(left * right);
} else if (op == "/") {
operands.emplace(left / right);
}
}
示例3: DFS
void DFS(GraphVertex* cur, stack<GraphVertex*> &vertex_order) {
cur->visited = true;
for (GraphVertex* &next : cur->edges) {
if (next->visited == false) {
DFS(next, vertex_order);
}
}
vertex_order.emplace(cur);
}
示例4:
static void
entry(const string &type)
{
#ifdef DEBUG
types.push(type);
recognition.emplace();
if (unrecognized.count(type) == 0) {
unrecognized[type] = set<string>();
}
#endif
}
示例5: delete
void operator delete(void* pMem)
{
lock_guard<mutex> lock{ s_Mutex };
const int index{
(static_cast<MyManagedObject*>(pMem)-s_ManagedObjects.data()) /
static_cast<intptr_t>(sizeof(MyManagedObject)) };
if (0 <= index && index < static_cast<int>(s_ManagedObjects.size()))
{
s_FreeList.emplace(static_cast<unsigned int>(index));
}
else
{
free(pMem);
}
}
示例6: produce
/// Produce \c element_count foos.
void produce(size_t element_count, size_t id_offset, stack& foos)
{
size_t id = id_offset;
{
lock_guard<mutex> _(g_io_mutex);
cout << this_thread::get_id() << " - produce from ID " << id << endl;
}
for (size_t i = 0; i < element_count; ++i) {
foos.emplace(foo(id++));
}
{
lock_guard<mutex> _(g_io_mutex);
cout << this_thread::get_id() << " - produced to ID " << id << endl;
}
}
示例7: expandNextNode
void Node::expandNextNode(stack<Node>& fringe)
{
auto x = get<0>(nextNodeMove);
auto y = get<1>(nextNodeMove);
// Has this function call already expanded a node.
// We need to keep track of this so that we can increment nextNodeMove
// until it points to the next valid move.
auto expanded = false;
for (/* y */; y < 3; ++y)
{
for (/* first init x as stored value, then 0 */ ; x < 3; ++x)
{
if (state->isFree(x, y))
{
if (!expanded)
{
// Add child state to the fringe
auto newBoard = make_unique<GameBoard>(*state);
auto newMove = make_unique<Move>(x, y);
newBoard->makeMove(*newMove);
fringe.emplace(Node{move(newBoard), this,
move(newMove), depth > 0 ? depth - 1 : 0,
alpha, beta, !maximizer});
expanded = true; // Only expand once per function call
}
else
{
// Save the coordinates of the next free space
nextNodeMove = decltype(nextNodeMove){ x, y };
return;
}
}
}
x = 0; // On a new row, so reset x to 0
}
// No more nodes found, so indicate that with an invalid move
nextNodeMove = decltype(nextNodeMove){ 3, 3 };
}
示例8: push
void push(const T &x) {
s.emplace(x, std::max(x, empty() ? x : s.top().second));
}
示例9: push
void push(int x) {
int minVal = d_stack.empty() ? x : min(x, d_stack.top().second);
d_stack.emplace(x, minVal);
}