forked from OSchip/llvm-project
parent
06b6c4bbde
commit
2c07348696
|
@ -187,79 +187,6 @@ inline ItTy prior(ItTy it)
|
|||
return it;
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Extra additions to <algorithm>
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// apply_until - Apply a functor to a sequence continually, unless the
|
||||
// functor returns true. Return true if the functor returned true, return false
|
||||
// if the functor never returned true.
|
||||
//
|
||||
template <class InputIt, class Function>
|
||||
bool apply_until(InputIt First, InputIt Last, Function Func) {
|
||||
for ( ; First != Last; ++First)
|
||||
if (Func(*First)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// reduce - Reduce a sequence values into a single value, given an initial
|
||||
// value and an operator.
|
||||
//
|
||||
template <class InputIt, class Function, class ValueType>
|
||||
ValueType reduce(InputIt First, InputIt Last, Function Func, ValueType Value) {
|
||||
for ( ; First != Last; ++First)
|
||||
Value = Func(*First, Value);
|
||||
return Value;
|
||||
}
|
||||
|
||||
#if 1 // This is likely to be more efficient
|
||||
|
||||
// reduce_apply - Reduce the result of applying a function to each value in a
|
||||
// sequence, given an initial value, an operator, a function, and a sequence.
|
||||
//
|
||||
template <class InputIt, class Function, class ValueType, class TransFunc>
|
||||
inline ValueType reduce_apply(InputIt First, InputIt Last, Function Func,
|
||||
ValueType Value, TransFunc XForm) {
|
||||
for ( ; First != Last; ++First)
|
||||
Value = Func(XForm(*First), Value);
|
||||
return Value;
|
||||
}
|
||||
|
||||
#else // This is arguably more elegant
|
||||
|
||||
// reduce_apply - Reduce the result of applying a function to each value in a
|
||||
// sequence, given an initial value, an operator, a function, and a sequence.
|
||||
//
|
||||
template <class InputIt, class Function, class ValueType, class TransFunc>
|
||||
inline ValueType reduce_apply2(InputIt First, InputIt Last, Function Func,
|
||||
ValueType Value, TransFunc XForm) {
|
||||
return reduce(map_iterator(First, XForm), map_iterator(Last, XForm),
|
||||
Func, Value);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// reduce_apply_bool - Reduce the result of applying a (bool returning) function
|
||||
// to each value in a sequence. All of the bools returned by the mapped
|
||||
// function are bitwise or'd together, and the result is returned.
|
||||
//
|
||||
template <class InputIt, class Function>
|
||||
inline bool reduce_apply_bool(InputIt First, InputIt Last, Function Func) {
|
||||
return reduce_apply(First, Last, bitwise_or<bool>(), false, Func);
|
||||
}
|
||||
|
||||
|
||||
// map - This function maps the specified input sequence into the specified
|
||||
// output iterator, applying a unary function in between.
|
||||
//
|
||||
template <class InIt, class OutIt, class Functor>
|
||||
inline OutIt mapto(InIt Begin, InIt End, OutIt Dest, Functor F) {
|
||||
return copy(map_iterator(Begin, F), map_iterator(End, F), Dest);
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Extra additions to <utility>
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
Loading…
Reference in New Issue