aimstil  5.0.5
misc_sort.tpp
Go to the documentation of this file.
1 
2 
3 namespace til
4 {
5  //---------------------------------------------------------------------------
6 
7  template < typename TVector2D, typename T >
8  inline
9  TVector2D
10  sortedVector(T a, T b)
11  {
12  if (a > b) std::swap(a,b);
13  TVector2D res;
14  res[0] = a;
15  res[1] = b;
16  return res;
17  }
18 
19  //---------------------------------------------------------------------------
20 
21  template < typename TVector3D, typename T >
22  TVector3D
23  sorted_vector(T a, T b, T c)
24  {
25  til::sort(a, b, c);
26  TVector3D res;
27  res[0] = a;
28  res[1] = b;
29  res[2] = c;
30  return res;
31  }
32 
33  //---------------------------------------------------------------------------
34 
35  /// NB: the argument is passed by value *on purpose*.
36  template < typename TVector3D >
37  TVector3D
38  sorted_vector(TVector3D v)
39  {
40  til::sort(v[0], v[1], v[2]);
41  return v;
42  }
43 
44  //---------------------------------------------------------------------------
45 
46  template < typename T >
47  inline
48  std::pair<T,T>
49  make_sorted_pair(T a, T b)
50  {
51  if (a >= b)
52  return std::make_pair(a,b);
53  else
54  return std::make_pair(b,a);
55  }
56 
57  //---------------------------------------------------------------------------
58 
59 } // namespace til
60