[Rivet-svn] rivet: Add count function

Rivet Mercurial rivet at projects.hepforge.org
Mon Sep 12 15:30:02 BST 2016


details:   https://rivet.hepforge.org/hg/rivet/rev/d867f69e6590
branches:  release-2-5-x
changeset: 5453:d867f69e6590
user:      Holger Schulz <holger.schulz at durham.ac.uk>
date:      Mon Sep 12 15:19:52 2016 +0100
description:
Add count function

diffs (25 lines):

--- a/ChangeLog	Thu Sep 08 22:48:15 2016 +0100
+++ b/ChangeLog	Mon Sep 12 15:19:52 2016 +0100
@@ -1,3 +1,7 @@
+2016-09-12  Holger Schulz  <holger.schulz at cern.ch>
+
+	* Add count function to Tools/Utils.h
+
 2016-09-08  Andy Buckley  <andy.buckley at cern.ch>
 
 	* Add C-array version of multi-target Analysis::scale() and normalize(), and fix (semantic) constness.
--- a/include/Rivet/Tools/Utils.hh	Thu Sep 08 22:48:15 2016 +0100
+++ b/include/Rivet/Tools/Utils.hh	Mon Sep 12 15:19:52 2016 +0100
@@ -208,6 +208,12 @@
     return std::all_of(std::begin(c), std::end(c), f);
   }
 
+  /// Return number of elements of container for which expression f is true.
+  template <typename CONTAINER, typename FN>
+  inline unsigned int count(const CONTAINER& c, const FN& f) {
+    return std::count_if(std::begin(c), std::end(c), f);
+  }
+
   /// Return true if @a f(x) is false for all @c x in container @a c, otherwise false.
   template <typename CONTAINER, typename FN>
   inline bool none(const CONTAINER& c, const FN& f) {


More information about the Rivet-svn mailing list