/* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ #ifndef ALGO_H #define ALGO_H #include #ifndef __GNUG__ #include #endif #include template Function for_each(InputIterator first, InputIterator last, Function f) { while (first != last) f(*first++); return f; } template InputIterator find(InputIterator first, InputIterator last, const T& value) { while (first != last && *first != value) ++first; return first; } template InputIterator find_if(InputIterator first, InputIterator last, Predicate pred) { while (first != last && !pred(*first)) ++first; return first; } template ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last) { if (first == last) return last; ForwardIterator next = first; while(++next != last) { if (*first == *next) return first; first = next; } return last; } template ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred) { if (first == last) return last; ForwardIterator next = first; while(++next != last) { if (binary_pred(*first, *next)) return first; first = next; } return last; } template void count(InputIterator first, InputIterator last, const T& value, Size& n) { while (first != last) if (*first++ == value) ++n; } template void count_if(InputIterator first, InputIterator last, Predicate pred, Size& n) { while (first != last) if (pred(*first++)) ++n; } /* template inline _OI transform(_II _F, _II _L, _OI _X, _Uop _U) {for (; _F != _L; ++_F, ++_X) *_X = _U(*_F); return (_X); } // TEMPLATE FUNCTION transform WITH BINARY OP template inline _OI transform(_II1 _F1, _II1 _L1, _II2 _F2, _OI _X, _Bop _B) {for (; _F1 != _L1; ++_F1, ++_F2, ++_X) *_X = _B(*_F1, *_F2); return (_X); } // TEMPLATE FUNCTION replace */ #endif