template <class ForwardIterator, class X> pair<ForwardIterator, ForwardIterator> equal_range( ForwardIterator xFirst, ForwardIterator xLast, const X& kxrValue );
#include <algorithm>
template <class ForwardIterator, class X, class Predicate> pair<ForwardIterator, ForwardIterator> equal_range( ForwardIterator xFirst, ForwardIterator xLast, const X& kxrValue, Predicate xTest );
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
using namespace std;
// Create an ordered vector instance
vector<int> qV;
qV.push_back(2);
qV.push_back(4);
qV.push_back(5);
qV.push_back(5);
qV.push_back(5);
qV.push_back(7);
qV.push_back(9);
// Calculate the range
pair<vector<int>::iterator, vector<int>::iterator> qRange
= equal_range(qV.begin(), qV.end(), 5);
// Output the entries in the range
vector<int>::iterator qIter;
cout << "Inside Range: ";
for (qIter = qRange.first; qIter != qRange.second; ++qIter) {
cout << *qIter << " ";
}
cout << endl;
// Output the range bounds inside the vector
cout << "Vector: ";
for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
if (qIter == qRange.first || qIter == qRange.second) {
cout << "| ";
}
cout << *qIter << " ";
}
cout << endl;
// Keep the window open
cin.get();
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.