HackAnalysis  2
Utils.h
1 // -*- C++ -*-
2 //
3 // This file is part of HEPUtils -- https://bitbucket.org/andybuckley/heputils
4 // Copyright (C) 2013-2018 Andy Buckley <andy.buckley@cern.ch>
5 //
6 // Embedding of HEPUtils code in other projects is permitted provided this
7 // notice is retained and the HEPUtils namespace and include path are changed.
8 //
9 
10 // Duly: HEPUtils namespace changed to HEP
11 
12 #pragma once
13 
14 #if defined(__cplusplus) && __cplusplus < 201103L
15 // #define XSTR(x) STR(x)
16 // #define STR(x) #x
17 // #pragma message STR(__cplusplus)
18 #error "This library needs at least a C++11 compliant compiler"
19 #endif
20 
23 
24 namespace HEP {
25 
26 
28 
29 
31  template <typename CONTAINER, typename FN>
32  inline bool any(const CONTAINER& c, const FN& f) {
33  for (const typename CONTAINER::value_type& val : c) {
34  if (f(val)) return true;
35  }
36  return false;
37  }
38 
40  template <typename CONTAINER, typename FN>
41  inline bool all(const CONTAINER& c, const FN& f) {
42  for (const typename CONTAINER::value_type& val : c) {
43  if (!f(val)) return false;
44  }
45  return true;
46  }
47 
49  template <typename CONTAINER, typename T>
50  inline bool contains(const CONTAINER& c, const T& x) {
51  for (const typename CONTAINER::value_type& val : c) {
52  if (val == x) return true;
53  }
54  return false;
55  }
56 
57 
59 
60 
61 }
Modified by Mark Goodsell goodsell@lpthe.jussieu.fr
Definition: ATLAS_SUSY_2018_16.cc:27
bool contains(const CONTAINER &c, const T &x)
Return true if x is found in container c, otherwise false.
Definition: Utils.h:50
bool any(const CONTAINER &c, const FN &f)
Return true if f(x) is true for any x in container c, otherwise false.
Definition: Utils.h:32
bool all(const CONTAINER &c, const FN &f)
Return true if f(x) is true for all x in container c, otherwise false.
Definition: Utils.h:41