llvm.org GIT mirror llvm / b31d176
Add convenience utility for replacing a range within a container with a different range, in preparation for use in Clang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363617 91177308-0d34-0410-b5e6-96231b3b80d8 Richard Smith 29 days ago
1 changed file(s) with 27 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
13911391 C.erase(remove_if(C, P), C.end());
13921392 }
13931393
1394 /// Given a sequence container Cont, replace the range [ContIt, ContEnd) with
1395 /// the range [ValIt, ValEnd) (which is not from the same container).
1396 template
1397 void replace(Container &Cont, typename Container::iterator ContIt,
1398 typename Container::iterator ContEnd, RandomAccessIterator ValIt,
1399 RandomAccessIterator ValEnd) {
1400 while (true) {
1401 if (ValIt == ValEnd) {
1402 Cont.erase(ContIt, ContEnd);
1403 return;
1404 } else if (ContIt == ContEnd) {
1405 Cont.insert(ContIt, ValIt, ValEnd);
1406 return;
1407 }
1408 *ContIt++ = *ValIt++;
1409 }
1410 }
1411
1412 /// Given a sequence container Cont, replace the range [ContIt, ContEnd) with
1413 /// the range R.
1414 template
1415 typename Container::value_type>>
1416 void replace(Container &Cont, typename Container::iterator ContIt,
1417 typename Container::iterator ContEnd, Range R) {
1418 replace(Cont, ContIt, ContEnd, R.begin(), R.end());
1419 }
1420
13941421 //===----------------------------------------------------------------------===//
13951422 // Extra additions to
13961423 //===----------------------------------------------------------------------===//