Standard Template Library Programmer's Guide
Здесь есть возможность читать онлайн «Standard Template Library Programmer's Guide» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, Справочники, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.
- Название:Standard Template Library Programmer's Guide
- Автор:
- Жанр:
- Год:неизвестен
- ISBN:нет данных
- Рейтинг книги:4 / 5. Голосов: 1
-
Избранное:Добавить в избранное
- Отзывы:
-
Ваша оценка:
- 80
- 1
- 2
- 3
- 4
- 5
Standard Template Library Programmer's Guide: краткое содержание, описание и аннотация
Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Standard Template Library Programmer's Guide»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.
Standard Template Library Programmer's Guide — читать онлайн бесплатно полную книгу (весь текст) целиком
Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Standard Template Library Programmer's Guide», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
find , mismatch , equal , search
find_first_of
Category: algorithms
Component type: function
find_first_of is an overloaded name; there are actually two find_first_of functions.
template
InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2);
template
InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2, BinaryPredicate comp);
Find_first_of is similar to find , in that it performs linear seach through a range of Input Iterators. The difference is that while find searches for one particular value, find_first_of searches for any of several values. Specifically, find_first_of searches for the first occurrance in the range [first1, last1) of any of the elements in [first2, last2) . (Note that this behavior is reminiscent of the function strpbrk from the standard C library.)
The two versions of find_first_of differ in how they compare elements for equality. The first uses operator== , and the second uses and arbitrary user-supplied function object comp . The first version returns the first iterator i in [first1, last1) such that, for some iterator j in [first2, last2) , *i == *j . The second returns the first iterator i in [first1, last1) such that, for some iterator j in [first2, last2) , comp(*i, *j) is true . As usual, both versions return last1 if no such iterator i exists.
Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.
For the first version:
• InputIterator is a model of Input Iterator.
• ForwardIterator is a model of Forward Iterator.
• InputIterator 's value type is EqualityComparable , and can be compared for equality with ForwardIterator's value type.
For the second version:
• InputIterator is a model of Input Iterator.
• ForwardIterator is a model of Forward Iterator.
• BinaryPredicate is a model of Binary Predicate.
• InputIterator 's value type is convertible to BinaryPredicate 's first argument type.
• ForwardIterator 's value type is convertible to BinaryPredicate 's second argument type.
• [first1, last1) is a valid range.
• [first2, last2) is a valid range.
At most (last1 – first1) * (last2 – first2) comparisons.
Like strpbrk , one use for find_first_of is finding whitespace in a string; space, tab, and newline are all whitespace characters.
int main() {
const char* WS = "\t\n ";
const int n_WS = strlen(WS);
char* s1 = "This sentence contains five words.";
char* s2 = "OneWord";
char* end1 = find_first_of(s1, s1 + strlen(s1), WS, WS + n_WS);
char* end2 = find_first_of(s2, s2 + strlen(s2), WS, WS + n_WS);
printf("First word of s1: %.*s\n", end1 – s1, s1);
printf("First word of s2: %.*s\n", end2 – s2, s2);
}
find , find_if , search
count
Category: algorithms
Component type: function
Count is an overloaded name: there are two count functions.
template
iterator_traits::difference_type count(InputIterator first, InputIterator last, const EqualityComparable& value);
template
void count(InputIterator first, InputIterator last, const EqualityComparable& value, Size& n);
Count finds the number of elements in [first, last) that are equal to value . More precisely, the first version of count returns the number of iterators i in [first, last) such that *i == value . The second version of count adds to n the number of iterators i in [first, last) such that *i == value .
The second version of count was the one defined in the original STL, and the first version is the one defined in the draft C++ standard; the definition was changed because the older interface was clumsy and error-prone. The older interface required the use of a temporary variable, which had to be initialized to 0 before the call to count .
Both interfaces are currently supported [1], for reasons of backward compatibility, but eventually the older version will be removed.
Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.
For the first version, which takes three arguments:
• InputIterator is a model of Input Iterator.
• EqualityComparable is a model of Equality Comparable.
• InputIterator 's value type is a model of Equality Comparable.
• An object of InputIterator 's value type can be compared for equality with an object of type EqualityComparable .
For the second version, which takes four arguments:
• InputIterator is a model of Input Iterator.
• EqualityComparable is a model of Equality Comparable.
• Size is an integral type that can hold values of InputIterator 's distance type.
• InputIterator 's value type is a model of Equality Comparable.
• An object of InputIterator 's value type can be compared for equality with an object of type EqualityComparable .
• [first, last) is a valid range.
For the second version:
• [first, last) is a valid range.
• n plus the number of elements equal to value does not exceed the maximum value of type Size .
Linear. Exactly last – first comparisons.
int main() {
int A[] = { 2, 0, 4, 6, 0, 3, 1, –7 };
const int N = sizeof(A) / sizeof(int);
cout << "Number of zeros: " << count(A, A + N, 0) << endl;
}
[1] The new count interface uses the iterator_traits class, which relies on a C++ feature known as partial specialization . Many of today's compilers don't implement the complete standard; in particular, many compilers do not support partial specialization. If your compiler does not support partial specialization, then you will not be able to use the newer version of count , or any other STL components that involve iterator_traits .
Читать дальшеИнтервал:
Закладка:
Похожие книги на «Standard Template Library Programmer's Guide»
Представляем Вашему вниманию похожие книги на «Standard Template Library Programmer's Guide» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «Standard Template Library Programmer's Guide» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.