@specsoftdev live:.cid.8e17e9b93cabb607 specsoftdev@gmail.com
std::count
Актуально для C++23.

#include <algorithm>
Актуально на 2024-02-16.


Define overload #1
template<class InputIterator, class T>
constexpr inline
typename iterator_traits<InputIterator>::difference_type
count(InputIterator first, InputIterator last, const T& value);

Подсчитывает количество элементов в диапазоне [first, last] эквивалентных value.
Вернёт количество найденных элементов.
Example, possible implementation
Define overload #2
template <class ExecutionPolicy, class ForwardIterator, class T>
typename iterator_traits<ForwardIterator>::difference_type>
count(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, const T& value);

Example, possible implementation

Examples


Example 1:
#include <iostream>
#include <algorithm>

int main()
{
    auto list = {1, 2, 3, 1, 2, 3, 3};
    auto count3 = std::count(std::cbegin(list), std::cend(list), 3);
    auto count7 = std::count(std::cbegin(list), std::cend(list), 7);

    std::cout << "count3: " << count3 << std::endl;
    std::cout << "count7: " << count7 << std::endl;
    return 0;
}

count3: 3
count7: 0



Changelog

C++26
TODO
C++23
TODO
C++20
TODO
C++17
TODO
C++14
TODO
C++11
TODO


See also

TODO

This page was last modified on 2024-02-16