npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
areAllElementsUnique.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_AREALLELEMENTSUNIQUE_HH_
2 #define NPSTAT_AREALLELEMENTSUNIQUE_HH_
3 
4 /*!
5 // \file areAllElementsUnique.hh
6 //
7 // \brief A simple O(n^2) template function for checking if all elements in
8 // a container are unique. Works well with small containers.
9 //
10 // Author: I. Volobouev
11 //
12 // June 2015
13 */
14 
15 namespace npstat {
16  template<class Iter>
17  inline bool areAllElementsUnique(Iter begin, Iter const end)
18  {
19  for (; begin != end; ++begin)
20  {
21  Iter comp(begin);
22  for (++comp; comp != end; ++comp)
23  if (*comp == *begin)
24  return false;
25  }
26  return true;
27  }
28 
29 #ifdef SWIG
30  template<typename Numeric>
31  inline bool areAllElementsUnique2(const Numeric* x, const unsigned long xLen)
32  {
33  return areAllElementsUnique(x, x+xLen);
34  }
35 #endif // SWIG
36 }
37 
38 #endif // NPSTAT_AREALLELEMENTSUNIQUE_HH_
Definition: AbsArrayProjector.hh:14