本文整理汇总了C++中strvec::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ strvec::clear方法的具体用法?C++ strvec::clear怎么用?C++ strvec::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strvec
的用法示例。
在下文中一共展示了strvec::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eliminateDuplicates
//Eliminates duplicates from the global vars
void eliminateDuplicates(strvec& vecRef)
{
std::set<std::string> tempSet(vecRef.begin(), vecRef.end()); //sets only allow unique elements! just stuff the whole vector in, then:
vecRef.clear();
vecRef.assign(tempSet.begin(), tempSet.end());
}
示例2: parallelHelper
//Worker function. Start and end represent the #pragma line and the closing brace
//Drives all the work for a parallel
void parallelHelper(int start, int end)
{
//grab the necessary values from the #pragma line
std::string pragmaString = input.at(start);
strvec privVars = getConstructVars(pragmaString, "private");
strvec sharedVars = getConstructVars(pragmaString, "shared");
int numThreads = getNumThreads(pragmaString);
//save the values in a backup for redeclaration in an inner function
privVarBackup.clear();
for (int i = 0; i < privVars.size(); i++)
{
privVarBackup.push_back(privVars.at(i));
}
sharedVarBackup.clear();
for (int i = 0; i < sharedVars.size(); i++)
{
sharedVarBackup.push_back(sharedVars.at(i));
}
//create a vector for the new pthreads void* function
std::vector<std::string> newFunction;
//add to the new function
std::string newFuncName;
std::string smallNewFuncName = std::string("func").append(std::to_string(currentFunction));
newFuncName.append("void* func").append(std::to_string(currentFunction)).append("(void* paramStruct)");
newFunction.push_back(newFuncName);
currentFunction++;
newFunction.push_back("{");
//redeclare variables in the new function
redeclareVars(privVars, newFunction);
strvec privVarDeclarations;
redeclareVars(privVars, privVarDeclarations);
add(privVarDeclarations, totalPrivBackup);
//stick shared vars in the global vector for declaration later
redeclareVars(sharedVars, globalVars);
//copy the function code as-is
for (int i = start + 2; i < end; i++) //move start up to pass first bracket, < end to not include last bracket.
{
newFunction.push_back(input.at(i));
}
newFunction.push_back("}");
//delete the #pragma section
input.erase(input.begin() + start, input.begin() + end + 1);
//record the offset as start since we're going to be changing the size of the vector
int newOffset = start;
//set up the pthreads code
//first we need an array of pthread_t threadids with size = numthreads
std::string tempString = std::string("pthread_t threads[").append(std::to_string(numThreads)).append("];"); //TODO do we need to populate this?
input.insert(input.begin() + newOffset++, tempString);
//populate the threads[] array
std::string loopVar = std::string("uniqueVar").append(std::to_string(uniqueVarNum));
uniqueVarNum++;
tempString = std::string("for (int ").append(loopVar).append(" = 0; ").append(loopVar).append(" < ").append(std::to_string(numThreads)).append("; ").append(loopVar).append("++)");
input.insert(input.begin() + newOffset++, tempString);
input.insert(input.begin() + newOffset++, "{");
tempString = std::string("threads[").append(loopVar).append("] = ").append(loopVar).append(";");
input.insert(input.begin() + newOffset++, tempString);
input.insert(input.begin() + newOffset++, "}");
//now create the pthreads
for (int i = 0; i < numThreads; i++)
{
tempString = std::string("StartEnd paramStruct").append(std::to_string(i)).append(";");
input.insert(input.begin() + newOffset++, tempString);
tempString = std::string("paramStruct").append(std::to_string(i)).append(".threadNum = ").append(std::to_string(i)).append(";");
input.insert(input.begin() + newOffset++, tempString);
tempString = std::string("pthread_create(&threads[").append(std::to_string(i)).append("], NULL, ").append(smallNewFuncName).append(", (void*) ¶mStruct").append(std::to_string(i)).append(");");
input.insert(input.begin() + newOffset++, tempString);
}
//now set up a for loop to join the pthreads
loopVar = std::string("uniqueVar").append(std::to_string(uniqueVarNum));
uniqueVarNum++;
tempString = std::string("for (int ").append(loopVar).append(" = 0; ").append(loopVar).append(" < ").append(std::to_string(numThreads)).append("; ").append(loopVar).append("++)");
input.insert(input.begin() + newOffset++, tempString);
input.insert(input.begin() + newOffset++, "{");
tempString = std::string("pthread_join(threads[").append(loopVar).append("], NULL);");
input.insert(input.begin() + newOffset++, tempString);
input.insert(input.begin() + newOffset++, "}");
//insert the new stuff, in reverse order!!
insertAfterIncludes(newFunction); //first, new function
}