Namespaces
Variants

std::experimental::ranges:: equal

From cppreference.net
template < InputIterator I1, Sentinel < I1 > S1, InputIterator I2, Sentinel < I2 > S2,

class Pred = ranges:: equal_to <> ,
class Proj1 = ranges:: identity , class Proj2 = ranges:: identity >
requires IndirectlyComparable < I1, I2, Pred, Proj1, Proj2 >
bool equal ( I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred { } ,

Proj1 proj1 = Proj1 { } , Proj2 proj2 = Proj2 { } ) ;
(1) (ranges TS)
template < InputRange R1, InputRange R2, class Pred = ranges:: equal_to <> ,

class Proj1 = ranges:: identity , class Proj2 = ranges:: identity >
requires IndirectlyComparable < ranges:: iterator_t < R1 > , ranges:: iterator_t < R2 > ,
Pred, Proj1, Proj2 >
bool equal ( R1 && r1, R2 && r2, Pred pred = Pred { } ,

Proj1 proj1 = Proj1 { } , Proj2 proj2 = Proj2 { } ) ;
(2) (ranges TS)
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 > &&
IndirectlyComparable < I1, std:: decay_t < I2 > , Pred, Proj1, Proj2 >
bool equal ( I1 first1, S1 last1, I2 && first2_, Pred pred = Pred { } ,

Proj1 proj1 = Proj1 { } , Proj2 proj2 = Proj2 { } ) ;
(3) (ranges TS)
(사용 중단됨)
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 > &&
IndirectlyComparable < ranges:: iterator_t < R1 > , std:: decay_t < I2 > , Pred, Proj1, Proj2 >
bool equal ( R1 && r1, I2 && first2_, Pred pred = Pred { } ,

Proj1 proj1 = Proj1 { } , Proj2 proj2 = Proj2 { } ) ;
(4) (범위 TS)
(사용 중단됨)
1) 범위 [ first1 , last1 ) 가 범위 [ first2 , last2 ) 와 같으면 true 를 반환하고, 그렇지 않으면 false 를 반환합니다.
2) (1) 과 동일하지만, r1 을 첫 번째 소스 범위로, r2 를 두 번째 소스 범위로 사용합니다. 마치 ranges:: begin ( r1 ) first1 으로, ranges:: end ( r1 ) last1 으로, ranges:: begin ( r2 ) first2 로, 그리고 ranges:: end ( r2 ) last2 로 사용하는 것과 같습니다.
3) (1) 과 동일하지만, 첫 번째 범위가 소진되거나 첫 번째 불일치가 감지될 때 두 번째 범위가 종료된 것으로 간주합니다. 다음 코드와 동일합니다: return last1 == ranges:: mismatch ( first1, last1, std:: forward < I2 > ( first2_ ) , comp, proj1, proj2 ) . in1 ( ) ;
4) (3) 과 동일하지만, 첫 번째 소스 범위로 r1 을 사용하며, 마치 ranges:: begin ( r1 ) first1 으로, ranges:: end ( r1 ) last1 으로 사용하는 것과 같습니다.

두 범위는 동일한 수의 요소를 가지고, 범위 [ first1 , last1 ) 내의 모든 반복자 i 에 대해 ranges:: invoke ( pred, ranges:: invoke ( proj1, * i ) , ranges:: invoke ( proj2, * ( first2 + ( i - first1 ) ) ) ) true 인 경우 동일한 것으로 간주됩니다.

위에 설명된 선언들과는 별개로, 알고리즘 선언에 대한 실제 템플릿 매개변수의 개수와 순서는 명시되지 않습니다. 따라서 알고리즘을 호출할 때 명시적 템플릿 인수를 사용하는 경우, 해당 프로그램은 이식성이 없을 가능성이 높습니다.

목차

매개변수

first1, last1 - 첫 번째 요소 범위
r1 - 첫 번째 요소 범위
first2, last2 - 두 번째 요소 범위
r2 - 두 번째 요소 범위
first2_ - 두 번째 요소 범위의 시작점
pred - 투영된 요소에 적용할 조건자
proj1 - 첫 번째 범위의 요소에 적용할 투영
proj2 - 두 번째 범위의 요소에 적용할 투영

반환값

true 두 범위가 동일한 경우 반환하며, 그렇지 않으면 false 를 반환합니다.

참고 사항

ranges::equal std::unordered_set , std::unordered_multiset , std::unordered_map , 또는 std::unordered_multimap 의 반복자들로 형성된 범위들을 비교하는 데 사용되어서는 안 됩니다. 왜냐하면 두 컨테이너가 동일한 요소들을 저장하더라도 이러한 컨테이너들 내에서 요소들이 저장되는 순서가 다를 수 있기 때문입니다.

전체 컨테이너의 동등성을 비교할 때는 일반적으로 해당 컨테이너의 operator== 를 사용하는 것이 권장됩니다.

복잡도

1,2) 만약 SizedSentinel < S1, I1 > && SizedSentinel < S2, I2 > 가 만족되고 last1 - first1 ! = last2 - first2 인 경우, 술어와 투영 함수는 적용되지 않습니다. 그렇지 않으면, 최대 min( last1 - first1 , last2 - first2 )번 술어와 각 투영 함수가 적용됩니다.
3,4) 최대 last1 - first1 회의 술어 및 각 프로젝션 적용.

가능한 구현

namespace detail 
{
    template<InputIterator I1, SizedSentinel<I1> S1,
             InputIterator I2, SizedSentinel<I1> S2>
    bool check_size(I1& first1, S1& last1, I2& first2, S2& last2)
    {
        return last1 - first1 != last2 - first2;
    }
    template<InputIterator I1, Sentinel<I1> S1, InputIterator I2, Sentinel<I1> S2>
    bool check_size(I1& first1, S1& last1, I2& first2, S2& last2)
    {
        return false;
    }
}
template<InputIterator I1, Sentinel<I1> S1, InputIterator I2, Sentinel<I2> S2,
         class Pred = ranges::equal_to<>, 
         class Proj1 = ranges::identity, class Proj2 = ranges::identity>
    requires IndirectlyComparable<I1, I2, Pred, Proj1, Proj2>
bool equal(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{},
           Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) 
{
    if (detail::check_size(first1, last1, first2, last2))
        return false;
    for (; first1 != last1 && first2 != last2; (void) ++first1, (void)++first2)
        if (!ranges::invoke(pred, ranges::invoke(proj1, *first1), 
                                  ranges::invoke(proj2, *first2)))
            return false;
    return first1 == last1 && first2 == last2;
}

예제

참고 항목

두 원소 집합이 동일한지 판별합니다
(function template)
특정 조건을 만족하는 첫 번째 원소를 찾습니다
(function template)
한 범위가 다른 범위보다 사전순으로 작으면 true 를 반환합니다
(function template)
두 범위가 처음으로 달라지는 위치를 찾습니다
(function template)
원소들의 범위를 검색합니다
(function template)