std::experi...es::mismatch(3)
πΈ NAME πΈ
Okay bestie, this is the page for std::experi...es::mismatch from the C++ Standard Libary manual, and the full name is std::experimental::ranges::mismatch. Itβs giving βfind the first spot where two ranges stop matchingβ energy, and yes, the title really has that experi...es abbreviation β we keep it exactly as the source has it. π
β¨ Synopsis β¨
Defined in header <experimental/ranges/algorithm> β literal path, do not touch it. π«Ά
template< InputIterator I1, Sentinel<I1> S1, InputIterator I2,
Sentinel<I2> S2,
class Proj1 = ranges::identity, class Proj2 =
ranges::identity,
class Pred = ranges::equal_to<> >
requires IndirectRelation<Pred, projected<I1, Proj1>,
(1) (ranges TS)
projected<I2, Proj2>>
auto mismatch( I1 first1, S1 last1, I2 first2, S2 last2, Pred pred
= Pred{},
Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{} )
-> ranges::tagged_pair<tag::in1(I1), tag::in2(I2)>;
template< InputRange R1, InputRange R2,
class Proj1 = ranges::identity, class Proj2 =
ranges::identity,
class Pred = ranges::equal_to<> >
requires IndirectRelation<Pred,
projected<ranges::iterator_t<R1>, Proj1>,
(2) (ranges TS)
projected<ranges::iterator_t<R2>,
Proj2>>
auto mismatch( R1&& r1, R2&& r2, Pred pred = Pred{},
Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{} )
-> ranges::tagged_pair<tag::in1(ranges::safe_iterator_t<R1>),
tag::in2(ranges::safe_iterator_t<R2>)>;
template< InputIterator I1, Sentinel<I1> S1, class I2,
class Pred = ranges::equal_to<>,
class Proj1 = ranges::identity, class Proj2 =
ranges::identity >
requires InputIterator<std::decay_t<I2>> && !Range<I2> &&
IndirectRelation<Pred, projected<I1, Proj1>,
(ranges TS)
projected<std::decay_t<I2>,
(3) (deprecated)
Proj2>>
auto mismatch( I1 first1, S1 last1, I2&& first2_, Pred pred =
Pred{},
Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{} )
-> ranges::tagged_pair<tag::in1(I1),
tag::in2(std::decay_t<I2>)>;
template< InputRange R1, class I2, class Pred = ranges::equal_to<>,
class Proj1 = ranges::identity, class Proj2 =
ranges::identity >
requires InputIterator<std::decay_t<I2>> && !Range<I2> &&
IndirectRelation<Pred,
projected<ranges::iterator_t<R1>, Proj1>,
(4) (ranges TS)
projected<std::decay_t<I2>,
(deprecated)
Proj2>>
auto mismatch( R1&& r1, I2&& first2_, Pred pred = Pred{},
Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{} )
-> ranges::tagged_pair<tag::in1(ranges::safe_iterator_t<Rng1>),
tag::in2(std::decay_t<I2>)>;
- Returns the first mismatching pair of elements from two ranges: one defined by
[first1, last1)and another defined by[first2, last2). π - Same as (1), but uses
r1as the first source range andr2as the second source range, as if usingranges::begin(r1)asfirst1,ranges::end(r1)aslast1,ranges::begin(r2)asfirst2, andranges::end(r2)aslast2. β¨ - Same as (1), but behaves as if
first2isstd::decay_t<I2> first2 = std::forward<I2>(first2_);andlast2isranges::unreachable{}. The underlying algorithm never incrementsfirst2more thanlast1 - first1times. π«‘ - Same as (3), but uses
r1as the first source range, as if usingranges::begin(r1)asfirst1andranges::end(r1)aslast1. π
Elements are compared using pred to the projected elements of the two ranges, as if by ranges::invoke(pred, ranges::invoke(proj1, *i), ranges::invoke(proj2, *j)). No cap, thatβs the actual comparison vibe. π₯
Notwithstanding the declarations depicted above, the actual number and order of template parameters for algorithm declarations is unspecified. Thus, if explicit template arguments are used when calling an algorithm, the program is probably non-portable. β οΈ This is the βdo not assume the template parameter order is stableβ warning, bestie β keep it close.
π Parameters π
first1,last1β the first range of the elementsr1β the first range of the elementsfirst2,last2β the second range of the elementsr2β the second range of the elementsfirst2_β the beginning of the second range of the elementspredβ predicate to apply to the projected elementsproj1β projection to apply to the elements in the first rangeproj2β projection to apply to the elements in the second range
π Return value π
A tagged_pair object with iterators to the first two non-equal elements β the iterator from the first range has the tag in1, and the iterator from the second range has the tag in2. π·οΈβ¨
If no mismatches are found when the comparison reaches last1 or last2, whichever happens first, the pair holds the end iterator and the corresponding iterator from the other range. So yeah, it can absolutely return βwe ran out of rangeβ vibes, not just βfound a differenceβ vibes. π
π Complexity π
At most last1 - first1 applications of the predicate and each projection. Thatβs the budget, bestie β no secret extra passes. πΈ
π§ Possible implementation π§
template<InputIterator I1, Sentinel<I1> S1, InputIterator I2, Sentinel<I2> S2,
class Proj1 = ranges::identity, class Proj2 = ranges::identity,
class Pred = ranges::equal_to<>>
requires IndirectRelation<Pred, projected<I1, Proj1>, projected<I2, Proj2>>
auto mismatch(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{},
Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{})
-> ranges::tagged_pair<tag::in1(I1), tag::in2(I2)>
{
while (first1 != last1 && first2 != last2 &&
ranges::invoke(pred, ranges::invoke(proj1, *first1),
ranges::invoke(proj2, *first2)))
{
++first1;
++first2;
}
return {first1, first2};
}
π¦ Example π¦
This section is incomplete Reason: no example
Not me showing up with no example π β the source literally says itβs incomplete and gives βno exampleβ as the reason. We preserve the emptiness, bestie. π«Ά
β See also β
mismatchβ finds the first position where two ranges differ (function template)equalβ determines if two sets of elements are the same (function template)find,find_if,find_if_notβ finds the first element satisfying specific criteria (function template)lexicographical_compareβ returns true if one range is lexicographically less than another (function template)searchβ searches for a range of elements (function template)
π Category π
* Todo no example
xoxo, your C++ bestie π β source: http://cppreference.com, version/date: 2024.06.10, and the page is std::experi...es::mismatch(3). Bye bestie! π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms