Ignore:
Timestamp:
2018-07-05T21:41:22Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
026cb10
Parents:
7ca0410f
git-author:
Dzejrou <dzejrou@…> (2018-04-30 22:21:53)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
Message:

cpp: added lexicographical_compare

File:
1 edited

Legend:

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

    r7ca0410f r26d2990  
    10871087     */
    10881088
    1089     // TODO: implement
     1089    template<class InputIterator1, class InputIterator2>
     1090    bool lexicographical_compare(InputIterator1 first1,
     1091                                 InputIterator1 last1,
     1092                                 InputIterator2 first2,
     1093                                 InputIterator2 last2)
     1094    {
     1095        /**
     1096         * *first1 and *first2 can have different types
     1097         * so we use a transparent comparator.
     1098         */
     1099        return lexicographical_compare(
     1100            first1, last1, first2, last2,
     1101            less<void>{}
     1102        );
     1103    }
     1104
     1105    template<class InputIterator1, class InputIterator2, class Compare>
     1106    bool lexicographical_compare(InputIterator1 first1,
     1107                                 InputIterator1 last1,
     1108                                 InputIterator2 first2,
     1109                                 InputIterator2 last2,
     1110                                 Compare comp)
     1111    {
     1112        while ((first1 != last1) && (first2 != last2))
     1113        {
     1114            if (comp(*first1, *first2))
     1115                return true;
     1116            if (comp(*first2, *first1))
     1117                return false;
     1118
     1119            ++first1;
     1120            ++first2;
     1121        }
     1122
     1123        /**
     1124         * Up until now they are same, so we have to check
     1125         * if we reached the end on one.
     1126         */
     1127        return (first1 == last1) && (first2 != last2);
     1128    }
    10901129
    10911130    /**
Note: See TracChangeset for help on using the changeset viewer.