A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../algorithm/../header/../iterator/common_iterator.html below:

std::common_iterator - cppreference.com

std::common_iterator is an iterator I / sentinel S adaptor that may represent a non-common range (where the types of I and S differ) as a common_range, by containing either an iterator or a sentinel, and defining the appropriate equality comparison operators operator==.

std::common_iterator can be used as a "bridge" between sequences represented by iterator/sentinel pair and legacy functions that expect common_range-like sequences.

[edit] Data members Member name Definition var an object of type std::variant<I, S>
(exposition-only member object*) [edit] Member functions [edit] Non-member functions compares the underlying iterators or sentinels
(function template) [edit] computes the distance between two iterator adaptors
(function template) [edit] casts the result of dereferencing the underlying iterator to its associated rvalue reference type
(function) [edit] swaps the objects pointed to by two underlying iterators
(function template) [edit] [edit] Helper classes [edit] Example
#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>
#include <string>
 
template<class ForwardIter>
void fire(ForwardIter first, ForwardIter last)
{
    std::copy(first, last, std::ostream_iterator<std::string>{std::cout, " "});    
}
 
int main()
{
    std::list<std::string> stars{"Pollux", "Arcturus", "Mira", "Aldebaran", "Sun"};
 
    using IT = std::common_iterator<
                   std::counted_iterator<std::list<std::string>::iterator>,
                   std::default_sentinel_t>;
 
    fire(IT(std::counted_iterator(stars.begin(), stars.size() - 1)),
         IT(std::default_sentinel));
}

Output:

Pollux Arcturus Mira Aldebaran
[edit] References
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4