if (location != s + N) {

  cout << 'Found a match for ' << suffix << ' within ' << s << endl;

  cout << s << endl;

  int i;

  for (i = 0; i < (location – s); ++i) cout << ' ';

  for (i = 0; i < N_suf; ++i) cout << '^';

  cout << endl;

 } else cout << 'No match for ' << suffix << ' within ' << s << endl;

}

Notes

[1] The reason that this range is [first1, last1 – (last2 – first2)), instead of simply [first1, last1), is that we are looking for a subsequence that is equal to the complete sequence [first2, last2). An iterator i can't be the beginning of such a subsequence unless last1 – i is greater than or equal to last2 – first2. Note the implication of this: you may call find_end with arguments such that last1 – first1 is less than last2 – first2, but such a search will always fail.

See also

search

Mutating algorithms

copy

Category: algorithms

Component type: function

Prototype

template <class InputIterator, class OutputIterator>

OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result);

Description

Copy copies elements from the range [first, last) to the range [result, result + (last – first)). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), and so on. [1] Generally, for every integer n from 0 to last – first, copy performs the assignment *(result + n) = *(first + n). Assignments are performed in forward order, i.e. in order of increasing n. [2]

The return value is result + (last – first)

Definition

Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.

Requirements on types

• InputIterator is a model of Input Iterator.

• OutputIterator is a model of Output Iterator.

• InputIterator's value type is convertible to a type in OutputIterator's set of value types.

Preconditions

• [first, last) is a valid range.

• result is not an iterator within the range [first, last) .

• There is enough space to hold all of the elements being copied. More formally, the requirement is that [result, result + (last – first)) is a valid range. [1]

Complexity

Linear. Exactly last – first assignments are performed.

Example

vector<int> V(5);

iota(V.begin(), V.end(), 1);

list<int> L(V.size());

copy(V.begin(), V.end(), L.begin());

assert(equal(V.begin(), V.end(), L.begin()));

Notes

[1] Note the implications of this. Copy cannot be used to insert elements into an empty Container: it overwrites elements, rather than inserting elements. If you want to insert elements into a Sequence, you can either use its insert member function explicitly, or else you can use copy along with an insert_iterator adaptor.

[2] The order of assignments matters in the case where the input and output ranges overlap: copy may not be used if result is in the range [first, last). That is, it may not be used if the beginning of the output range overlaps with the input range, but it may be used if the end of the output range overlaps with the input range; copy_backward has opposite restrictions. If the two ranges are completely nonoverlapping, of course, then either algorithm may be used. The order of assignments also matters if result is an ostream_iterator, or some other iterator whose semantics depends on the order or assignments.

See also

copy_backward, copy_n

copy_n

Category: algorithms

Component type: function

Prototype

template <class InputIterator, class Size, class OutputIterator>

OutputIterator copy_n(InputIterator first, Size count, OutputIterator result);

Description

Copy_n copies elements from the range [first, first + n) to the range [result, result + n). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), and so on. Generally, for every integer i from 0 up to (but not including) n, copy_n performs the assignment *(result + i) = *(first + i). Assignments are performed in forward order, i.e. in order of increasing n. [1]

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату