STIR  6.2.0
min_positive_element.h
Go to the documentation of this file.
1 //
2 //
3 /*
4  Copyright (C) 2002- 2007, Hammersmith Imanet Ltd
5  This file is part of STIR.
6 
7  SPDX-License-Identifier: Apache-2.0
8 
9  See STIR/LICENSE.txt for details
10 */
11 
12 #ifndef __stir_min_positive_element_h_
13 #define __stir_min_positive_element_h_
14 
25 #include "stir/common.h"
26 #include <iostream>
27 START_NAMESPACE_STIR
28 
30 
43 template <typename ForwardIter_t>
44 ForwardIter_t
45 min_positive_element(ForwardIter_t start, ForwardIter_t end)
46 {
47  // go and look for the first (strictly) positive number
48  while (start != end && *start <= 0)
49  ++start;
50  if (start == end)
51  return end;
52 
53  // now look through the rest for a smaller positive number
54  ForwardIter_t result = start;
55  while (++start != end)
56  if (!(*start <= 0) && *start < *result)
57  result = start;
58 
59  return result;
60 }
61 
62 END_NAMESPACE_STIR
63 #endif
ForwardIter_t min_positive_element(ForwardIter_t start, ForwardIter_t end)
Finds where the smallest strictly positive element occurs.
Definition: min_positive_element.h:45
basic configuration include file