Skip to content

Commit a05f4f6

Browse files
committed
[stl-extras] Add a range version of std::accumulate.
1 parent 6d09c7a commit a05f4f6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

include/swift/Basic/STLExtras.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#include "llvm/ADT/Optional.h"
2222
#include "llvm/ADT/STLExtras.h"
2323
#include "llvm/Support/Casting.h"
24+
#include <algorithm>
2425
#include <cassert>
2526
#include <functional>
2627
#include <iterator>
28+
#include <numeric>
2729
#include <type_traits>
28-
#include <algorithm>
2930

3031
namespace swift {
3132

@@ -786,6 +787,11 @@ inline OutputIterator transform(const Container &C, OutputIterator result,
786787
return std::transform(C.begin(), C.end(), result, op);
787788
}
788789

790+
template <typename Container, typename T, typename BinaryOperation>
791+
inline T accumulate(const Container &C, T init, BinaryOperation op) {
792+
return std::accumulate(C.begin(), C.end(), init, op);
793+
}
794+
789795
/// Provides default implementations of !=, <=, >, and >= based on == and <.
790796
template <typename T>
791797
class RelationalOperationsBase {

0 commit comments

Comments
 (0)