TuringSim
C++ framework to simulate abstract computing models
compare.h
1 #pragma once
2 
3 namespace TuringSim::Utils {
8  template <typename T>
9  struct Compare {
15  static int compare(const T& lhs, const T& rhs) {
16  if(lhs < rhs) {
17  return -1;
18  }
19  if(rhs < lhs) {
20  return 1;
21  }
22  return 0;
23  }
24  };
25 
28  template <>
29  struct Compare<std::string> {
35  static int compare(const std::string& lhs, const std::string& rhs) {
36  return lhs.compare(rhs);
37  }
38  };
39 
46  template <typename T>
47  int compare(const T& lhs, const T& rhs) {
48  return Compare<T>::compare(lhs, rhs);
49  }
50 }
TuringSim::Utils
The namespace for basic function, not specific to TuringSim.
TuringSim::Utils::compare
int compare(const T &lhs, const T &rhs)
To compare things.
Definition: compare.h:47
TuringSim::Utils::Compare::compare
static int compare(const T &lhs, const T &rhs)
Compare elements with a strong total order.
Definition: compare.h:15
TuringSim::Utils::Compare
A class to compare values with a strong total order. The generic way use operator<.
Definition: compare.h:9
TuringSim::Utils::Compare< std::string >::compare
static int compare(const std::string &lhs, const std::string &rhs)
Compare elements with a strong total order.
Definition: compare.h:35