Changeset 1668862 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:24Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
71f713a
Parents:
09416c12
git-author:
Dzejrou <dzejrou@…> (2018-05-18 17:44:03)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:24)
Message:

cpp: fixed std::equal, it used the iterators as if they were random access iterator, which they don't have to be

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/algorithm.hpp

    r09416c12 r1668862  
    224224                                                  InputIterator2 first2)
    225225    {
    226         while (first1 != last1 && *first1++ == *first2++)
    227         { /* DUMMY BODY */ }
     226        while (first1 != last1 && *first1 == *first2)
     227        {
     228            ++first1;
     229            ++first2;
     230        }
    228231
    229232        return make_pair(first1, first2);
     
    234237                                                  InputIterator2 first2, BinaryPredicate pred)
    235238    {
    236         while (first1 != last1 && pred(*first1++, *first2++))
    237         { /* DUMMY BODY */ }
     239        while (first1 != last1 && pred(*first1, *first2))
     240        {
     241            ++first1;
     242            ++first2;
     243        }
    238244
    239245        return make_pair(first1, first2);
     
    244250                                                  InputIterator2 first2, InputIterator2 last2)
    245251    {
    246         while (first1 != last1 && first2 != last2 && *first1++ == *first2++)
    247         { /* DUMMY BODY */ }
     252        while (first1 != last1 && first2 != last2 && *first1 == *first2)
     253        {
     254            ++first1;
     255            ++first2;
     256        }
    248257
    249258        return make_pair(first1, first2);
     
    255264                                                  BinaryPredicate pred)
    256265    {
    257         while (first1 != last1 && first2 != last2 && pred(*first1++, *first2++))
    258         { /* DUMMY BODY */ }
     266        while (first1 != last1 && first2 != last2 && pred(*first1, *first2))
     267        {
     268            ++first1;
     269            ++first2;
     270        }
    259271
    260272        return make_pair(first1, first2);
     
    268280    bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
    269281    {
    270         auto last2 = first2 + (last1 - first1);
    271 
    272         return equal(first1, last1, first2, last2);
     282        while (first1 != last1)
     283        {
     284            if (*first1++ != *first2++)
     285                return false;
     286        }
     287
     288        return true;
    273289    }
    274290
     
    277293               InputIterator2 first2, InputIterator2 last2)
    278294    {
    279         if ((last1 - first1) != (last2 - first2))
    280             return false;
    281 
    282         while (first1 != last1)
     295        while (first1 != last1 && first2 != last2)
    283296        {
    284297            if (*first1++ != *first2++)
     
    293306               InputIterator2 first2, BinaryPredicate pred)
    294307    {
    295         auto last2 = first2 + (last1 - first1);
    296 
    297         return equal(first1, last1, first2, last2, pred);
     308        while (first1 != last1)
     309        {
     310            if (!pred(*first1++, *first2++))
     311                return false;
     312        }
     313
     314        return true;
    298315    }
    299316
     
    303320               BinaryPredicate pred)
    304321    {
    305         if ((last1 - first1) != (last2 - first2))
    306             return false;
    307 
    308         while (first1 != last1)
     322        while (first1 != last1 && first2 != last2)
    309323        {
    310324            if (!pred(*first1++, *first2++))
Note: See TracChangeset for help on using the changeset viewer.