d08 ex01 change addnumber(range) to match official container way of doing it
This commit is contained in:
@@ -75,15 +75,28 @@ void Span::addNumber(int nb) {
|
||||
_sort.push_back(nb);
|
||||
std::sort(_sort.begin(), _sort.end());
|
||||
}
|
||||
void Span::addNumber(int * arr, unsigned int len) {
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
//void Span::addNumber(int * arr, unsigned int len) {
|
||||
// for (unsigned int i = 0; i < len; i++) {
|
||||
// if (_container.size() >= _max)
|
||||
// throw std::out_of_range(B_RED "out of range number" RESET);
|
||||
// _container.push_back(arr[i]);
|
||||
// _sort.push_back(arr[i]);
|
||||
// }
|
||||
// std::sort(_sort.begin(), _sort.end());
|
||||
//}
|
||||
template <class InputIterator>
|
||||
void Span::addNumber(InputIterator first, InputIterator last) {
|
||||
if (last < first)
|
||||
throw std::out_of_range(B_RED "bad iterators" RESET);
|
||||
for (; first != last; first++) {
|
||||
if (_container.size() >= _max)
|
||||
throw std::out_of_range(B_RED "out of range number" RESET);
|
||||
_container.push_back(arr[i]);
|
||||
_sort.push_back(arr[i]);
|
||||
_container.push_back(*first);
|
||||
_sort.push_back(*first);
|
||||
}
|
||||
std::sort(_sort.begin(), _sort.end());
|
||||
}
|
||||
template void Span::addNumber<int*>(int*, int*);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user