Similar to this question, but in C++. Although my priority is performance (and correctness!) rather than readability.#include <algorithm>#include <iterator>#include <cstddef>template <typename Container>size_t count_unique(const Container& elements){    size_t result {};    for (auto it = std::cbegin(elements), last = std::cend(elements); it != last;) {        ++result;        it = std::upper_bound(it, last, *it);    }    return result;}
Counting number of unique elements in a sorted container
c++;algorithm;c++14