WWW.DISSERS.RU

БЕСПЛАТНАЯ ЭЛЕКТРОННАЯ БИБЛИОТЕКА

   Добро пожаловать!


Pages:     | 1 |   ...   | 13 | 14 || 16 |

} template void basic_string<_CharT,_Traits,_Alloc> ::insert(basic_string<_CharT,_Traits,_Alloc>::iterator position, size_t n, _CharT c) { if (n != 0) { - 114 - УМП «Автоматизированные методы разработки архитектуры ПО» if (size_type(_M_end_of_storage - _M_finish) >= n + 1) { const size_type elems_after = _M_finish - position;

iterator old_finish = _M_finish;

if (elems_after >= n) { uninitialized_copy((_M_finish - n) + 1, _M_finish + 1, _M_finish + 1);

_M_finish += n;

_Traits::move(position + n, position, (elems_after - n) + 1);

_Traits::assign(position, n, c);

} else { uninitialized_fill_n(_M_finish + 1, n - elems_after - 1, c);

_M_finish += n - elems_after;

STL_TRY { uninitialized_copy(position, old_finish + 1, _M_finish);

_M_finish += elems_after;

} STL_UNWIND((destroy(old_finish + 1, _M_finish), _M_finish = old_finish));

_Traits::assign(position, elems_after + 1, c);

} } else { const size_type old_size = size();

const size_type len = old_size + max(old_size, n) + 1;

iterator new_start = _M_allocate(len);

iterator new_finish = new_start;

STL_TRY { new_finish = uninitialized_copy(_M_start, position, new_start);

new_finish = uninitialized_fill_n(new_finish, n, c);

new_finish = uninitialized_copy(position, _M_finish, new_finish);

_M_construct_null(new_finish);

} STL_UNWIND((destroy(new_start,new_finish), _M_deallocate(new_start,len)));

destroy(_M_start, _M_finish + 1);

_M_deallocate_block();

_M_start = new_start;

_M_finish = new_finish;

_M_end_of_storage = new_start + len;

} } } #ifdef STL_MEMBER_TEMPLATES template template void basic_string<_Tp, _Traits, _Alloc>::insert(iterator p, _InputIter first, _InputIter last, input_iterator_tag) { for ( ; first != last; ++first) { p = insert(p, *first);

++p;

} } template template void basic_string<_CharT,_Traits,_Alloc>::insert(iterator position, _ForwardIter first, _ForwardIter last, forward_iterator_tag) { if (first != last) { difference_type n = 0;

distance(first, last, n);

if (_M_end_of_storage - _M_finish >= n + 1) { const difference_type elems_after = _M_finish - position;

iterator old_finish = _M_finish;

if (elems_after >= n) { uninitialized_copy((_M_finish - n) + 1, _M_finish + 1, _M_finish + 1);

_M_finish += n;

_Traits::move(position + n, - 115 - УМП «Автоматизированные методы разработки архитектуры ПО» position, (elems_after - n) + 1);

_M_copy(first, last, position);

} else { _ForwardIter mid = first;

advance(mid, elems_after + 1);

uninitialized_copy(mid, last, _M_finish + 1);

_M_finish += n - elems_after;

STL_TRY { uninitialized_copy(position, old_finish + 1, _M_finish);

_M_finish += elems_after;

} STL_UNWIND((destroy(old_finish + 1, _M_finish), _M_finish = old_finish));

_M_copy(first, mid, position);

} } else { const size_type old_size = size();

const size_type len = old_size + max(old_size, static_cast(n)) + 1;

pointer new_start = _M_allocate(len);

pointer new_finish = new_start;

STL_TRY { new_finish = uninitialized_copy(_M_start, position, new_start);

new_finish = uninitialized_copy(first, last, new_finish);

new_finish = uninitialized_copy(position, _M_finish, new_finish);

_M_construct_null(new_finish);

} STL_UNWIND((destroy(new_start,new_finish), _M_deallocate(new_start,len)));

destroy(_M_start, _M_finish + 1);

_M_deallocate_block();

_M_start = new_start;

_M_finish = new_finish;

_M_end_of_storage = new_start + len;

} } } #else /* STL_MEMBER_TEMPLATES */ template void basic_string<_CharT,_Traits,_Alloc>::insert(iterator position, const _CharT* first, const _CharT* last) { if (first != last) { const ptrdiff_t n = last - first;

if (_M_end_of_storage - _M_finish >= n + 1) { const ptrdiff_t elems_after = _M_finish - position;

iterator old_finish = _M_finish;

if (elems_after >= n) { uninitialized_copy((_M_finish - n) + 1, _M_finish + 1, _M_finish + 1);

_M_finish += n;

_Traits::move(position + n, position, (elems_after - n) + 1);

_M_copy(first, last, position);

} else { const _CharT* mid = first;

advance(mid, elems_after + 1);

uninitialized_copy(mid, last, _M_finish + 1);

_M_finish += n - elems_after;

STL_TRY { uninitialized_copy(position, old_finish + 1, _M_finish);

_M_finish += elems_after;

} STL_UNWIND((destroy(old_finish + 1, _M_finish), _M_finish = old_finish));

_M_copy(first, mid, position);

} } else { const size_type old_size = size();

const size_type len = old_size + max(old_size, static_cast(n)) + 1;

- 116 - УМП «Автоматизированные методы разработки архитектуры ПО» pointer new_start = _M_allocate(len);

pointer new_finish = new_start;

STL_TRY { new_finish = uninitialized_copy(_M_start, position, new_start);

new_finish = uninitialized_copy(first, last, new_finish);

new_finish = uninitialized_copy(position, _M_finish, new_finish);

_M_construct_null(new_finish);

} STL_UNWIND((destroy(new_start,new_finish), _M_deallocate(new_start,len)));

destroy(_M_start, _M_finish + 1);

_M_deallocate_block();

_M_start = new_start;

_M_finish = new_finish;

_M_end_of_storage = new_start + len;

} } } #endif /* STL_MEMBER_TEMPLATES */ template basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc> ::replace(iterator first, iterator last, size_type n, _CharT c) { const size_type len = static_cast(last - first);

if (len >= n) { _Traits::assign(first, n, c);

erase(first + n, last);

} else { _Traits::assign(first, len, c);

insert(last, n - len, c);

} return *this;

} #ifdef STL_MEMBER_TEMPLATES template template basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc> ::replace(iterator first, iterator last, _InputIter f, _InputIter l, input_iterator_tag) { for ( ; first != last && f != l; ++first, ++f) _Traits::assign(*first, *f);

if (f == l) erase(first, last);

else insert(last, f, l);

return *this;

} template template basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc> ::replace(iterator first, iterator last, _ForwardIter f, _ForwardIter l, forward_iterator_tag) { difference_type n = 0;

distance(f, l, n);

const difference_type len = last - first;

if (len >= n) { _M_copy(f, l, first);

erase(first + n, last);

} else { _ForwardIter m = f;

advance(m, len);

_M_copy(f, m, first);

insert(last, m, l);

} return *this;

- 117 - УМП «Автоматизированные методы разработки архитектуры ПО» } #else /* STL_MEMBER_TEMPLATES */ template basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc> ::replace(iterator first, iterator last, const _CharT* f, const _CharT* l) { const ptrdiff_t n = l - f;

const difference_type len = last - first;

if (len >= n) { _M_copy(f, l, first);

erase(first + n, last);

} else { const _CharT* m = f + len;

_M_copy(f, m, first);

insert(last, m, l);

} return *this;

} #endif /* STL_MEMBER_TEMPLATES */ template basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc> ::find(const _CharT* s, size_type pos, size_type n) const { if (pos + n > size()) return npos;

else { const const_iterator result = search(_M_start + pos, _M_finish, s, s + n, _Eq_traits<_Traits>());

return result != _M_finish result - begin() : npos;

} } template basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc> ::find(_CharT c, size_type pos) const { if (pos >= size()) return npos;

else { const const_iterator result = find_if(_M_start + pos, _M_finish, bind2nd(_Eq_traits<_Traits>(), c));

return result != _M_finish result - begin() : npos;

} } template basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc> ::rfind(const _CharT* s, size_type pos, size_type n) const { const size_t len = size();

if (n > len) return npos;

else if (n == 0) return min(len, pos);

else { const const_iterator last = begin() + min(len - n, pos) + n;

const const_iterator result = find_end(begin(), last, s, s + n, _Eq_traits<_Traits>());

return result != last result - begin() : npos;

} } template basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc> ::rfind(_CharT c, size_type pos) const - 118 - УМП «Автоматизированные методы разработки архитектуры ПО» { const size_type len = size();

if (len < 1) return npos;

else { const const_iterator last = begin() + min(len - 1, pos) + 1;

const_reverse_iterator rresult = find_if(const_reverse_iterator(last), rend(), bind2nd(_Eq_traits<_Traits>(), c));

return rresult != rend() (rresult.base() - 1) - begin() : npos;

} } template basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc> ::find_first_of(const _CharT* s, size_type pos, size_type n) const { if (pos >= size()) return npos;

else { const_iterator result = STD::find_first_of(begin() + pos, end(), s, s + n, _Eq_traits<_Traits>());

return result != _M_finish result - begin() : npos;

} } template basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc> ::find_last_of(const _CharT* s, size_type pos, size_type n) const { const size_type len = size();

if (len < 1) return npos;

else { const const_iterator last = _M_start + min(len - 1, pos) + 1;

const const_reverse_iterator rresult = STD::find_first_of(const_reverse_iterator(last), rend(), s, s + n, _Eq_traits<_Traits>());

return rresult != rend() (rresult.base() - 1) - _M_start : npos;

} } template basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(const _CharT* s, size_type pos, size_type n) const { if (pos > size()) return npos;

else { const_iterator result = find_if(_M_start + pos, _M_finish, _Not_within_traits<_Traits>(s, s + n));

return result != _M_finish result - _M_start : npos;

} } template basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(_CharT c, size_type pos) const { if (pos > size()) return npos;

else { const_iterator result = find_if(begin() + pos, end(), not1(bind2nd(_Eq_traits<_Traits>(), c)));

return result != _M_finish result - begin() : npos;

} } template - 119 - УМП «Автоматизированные методы разработки архитектуры ПО» basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc> ::find_last_not_of(const _CharT* s, size_type pos, size_type n) const { const size_type len = size();

if (len < 1) return npos;

else { const const_iterator last = begin() + min(len - 1, pos) + 1;

const const_reverse_iterator rresult = find_if(const_reverse_iterator(last), rend(), _Not_within_traits<_Traits>(s, s + n));

return rresult != rend() (rresult.base() - 1) - begin() : npos;

} } template basic_string<_Tp, _Traits, _Alloc>::size_type basic_string<_Tp, _Traits, _Alloc> ::find_last_not_of(_Tp c, size_type pos) const { const size_type len = size();

if (len < 1) return npos;

else { const const_iterator last = begin() + min(len - 1, pos) + 1;

const_reverse_iterator rresult = find_if(const_reverse_iterator(last), rend(), not1(bind2nd(_Eq_traits<_Traits>(), c)));

return rresult != rend() (rresult.base() - 1) - begin() : npos;

} } // ------------------------------------------------------------ // Non-member functions.

// Operator+ template inline basic_string<_CharT,_Traits,_Alloc> operator+(const basic_string<_CharT,_Traits,_Alloc>& x, const basic_string<_CharT,_Traits,_Alloc>& y) { typedef basic_string<_CharT,_Traits,_Alloc> _Str;

typedef typename _Str::_Reserve_t _Reserve_t;

_Reserve_t reserve;

_Str result(reserve, x.size() + y.size(), x.get_allocator());

result.append(x);

result.append(y);

return result;

} template inline basic_string<_CharT,_Traits,_Alloc> operator+(const _CharT* s, const basic_string<_CharT,_Traits,_Alloc>& y) { typedef basic_string<_CharT,_Traits,_Alloc> _Str;

typedef typename _Str::_Reserve_t _Reserve_t;

_Reserve_t reserve;

const size_t n = _Traits::length(s);

_Str result(reserve, n + y.size());

result.append(s, s + n);

result.append(y);

return result;

} template inline basic_string<_CharT,_Traits,_Alloc> operator+(_CharT c, const basic_string<_CharT,_Traits,_Alloc>& y) { typedef basic_string<_CharT,_Traits,_Alloc> _Str;

typedef typename _Str::_Reserve_t _Reserve_t;

_Reserve_t reserve;

_Str result(reserve, 1 + y.size());

result.push_back(c);

result.append(y);

return result;

- 120 - УМП «Автоматизированные методы разработки архитектуры ПО» } template inline basic_string<_CharT,_Traits,_Alloc> operator+(const basic_string<_CharT,_Traits,_Alloc>& x, const _CharT* s) { typedef basic_string<_CharT,_Traits,_Alloc> _Str;

typedef typename _Str::_Reserve_t _Reserve_t;

_Reserve_t reserve;

const size_t n = _Traits::length(s);

_Str result(reserve, x.size() + n, x.get_allocator());

result.append(x);

result.append(s, s + n);

return result;

} template inline basic_string<_CharT,_Traits,_Alloc> operator+(const basic_string<_CharT,_Traits,_Alloc>& x, const _CharT c) { typedef basic_string<_CharT,_Traits,_Alloc> _Str;

typedef typename _Str::_Reserve_t _Reserve_t;

_Reserve_t reserve;

_Str result(reserve, x.size() + 1, x.get_allocator());

result.append(x);

result.push_back(c);

return result;

} // Operator== and operator!= template inline bool operator==(const basic_string<_CharT,_Traits,_Alloc>& x, const basic_string<_CharT,_Traits,_Alloc>& y) { return x.size() == y.size() && _Traits::compare(x.data(), y.data(), x.size()) == 0;

} template inline bool operator==(const _CharT* s, const basic_string<_CharT,_Traits,_Alloc>& y) { size_t n = _Traits::length(s);

return n == y.size() && _Traits::compare(s, y.data(), n) == 0;

} template inline bool operator==(const basic_string<_CharT,_Traits,_Alloc>& x, const _CharT* s) { size_t n = _Traits::length(s);

return x.size() == n && _Traits::compare(x.data(), s, n) == 0;

Pages:     | 1 |   ...   | 13 | 14 || 16 |






















© 2011 www.dissers.ru - «Бесплатная электронная библиотека»

Материалы этого сайта размещены для ознакомления, все права принадлежат их авторам.
Если Вы не согласны с тем, что Ваш материал размещён на этом сайте, пожалуйста, напишите нам, мы в течении 1-2 рабочих дней удалим его.