本文整理汇总了C++中ExprVector::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ ExprVector::reserve方法的具体用法?C++ ExprVector::reserve怎么用?C++ ExprVector::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExprVector
的用法示例。
在下文中一共展示了ExprVector::reserve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Flatten
// Flatten out all expressions with a given head.
void Expression::Flatten(const string head)
{
ExprVector newLeaves;
newLeaves.reserve(leaves.size());
for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf)
if((*leaf)->FunctionName() == head)
{
for(ExprVector::const_iterator subLeaf = (*leaf)->Leaves().begin(); subLeaf != (*leaf)->Leaves().end(); ++subLeaf)
newLeaves.push_back(*subLeaf);
(*leaf)->Leaves().clear();
delete *leaf;
}
else
newLeaves.push_back(*leaf);
leaves = newLeaves;
}
示例2: Evaluate
//.........这里部分代码省略.........
Evaluate(calculator, recursions + 1);
return;
}
}
}
// Apply Flat attribute
if(attributes.Contains(atFlat))
{
Flatten(FunctionName());
}
// Apply OneIdentity attribute
if(attributes.Contains(atOneIdentity))
{
if(ApplyOneIdentity())
return;
}
// Apply Listable attribute
if(attributes.Contains(atListable))
{
// Determine resulting list length, check if there are lists with different lengths
bool listFound(false);
ExprVector::size_type listSize(0);
for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf)
if((*leaf)->FunctionName() == "List")
if(!listFound)
{
listSize = (*leaf)->LeafCount();
listFound = true;
}
else
if(listSize != (*leaf)->LeafCount())
throw EvaluateException("Listable operation requires lists of the same length.");
// Construct resulting list
if(listFound)
{
ExprVector items;
// Number of resulting list items = items in operand list
items.reserve(listSize);
// Loop through list items
for(ExprVector::size_type position = 0; position < listSize; ++position)
{
// List item = function call, number of operands = number of original operands
Expression *item = new Expression(FunctionName(), leaves.size());
for(ExprVector::iterator itemLeaf = leaves.begin(); itemLeaf != leaves.end(); ++itemLeaf)
{
if((*itemLeaf)->FunctionName() == "List")
{
// Add corresponding list item
item->AppendLeaf(*((*itemLeaf)->leaves.begin() + position));
}
else
{
// Add "whole" item (clone if necessary)
if(position == 0)
item->AppendLeaf(*itemLeaf);
else
item->AppendLeaf((*itemLeaf)->Clone());
}
}
items.push_back(item);
}
// Delete lists (elements are now in resulting list)
for(ExprVector::iterator itemLeaf = leaves.begin(); itemLeaf != leaves.end(); ++itemLeaf)
if((*itemLeaf)->FunctionName() == "List")
{
(*itemLeaf)->leaves.clear();
delete *itemLeaf;
}
delete head;
head = new Expression("List");
leaves = items;
// Evaluate the list for itself
Evaluate(calculator, recursions);
return;
}
}
// Apply Orderless attribute
if(attributes.Contains(atOrderless))
{
std::sort(leaves.begin(), leaves.end(), &Compare);
}
// Apply down value rules
bool changed(false);
if(def->ApplyDownValues(this, calculator, &changed))
{
if(changed)
Evaluate(calculator, recursions + 1);
return;
}
// Execute linked operator, if specified
if(def->Predef())
def->Predef()->Apply(this, calculator, recursions);
}
else
{
// Otherwise simply evaluate the leaves
for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf)
(*leaf)->Evaluate(calculator, recursions);
}
}