title: C++: Why does numeric_limits work on types it does not know?
body: <p>I have created my own type, without any comparator, and without a specialization of <code>std::numeric_limits</code>. Despite that, for some reason, <code>std::numeric_limits&lt;MyType&gt;</code> compiles fine. Why did the c++ standards committee define the <code>numeric_limits</code> template such that it is valid for all types, including non-numeric types?? </p>
  
  <p>Example code below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;limits&gt;
  using namespace std;
  
  // This is an int wrapper that defaults to 666 instead of 0
  class A {
  public:
      int x;
  public:
      A() : x(666) {}
  };
  
  int main() {
      A a = std::numeric_limits&lt;A&gt;::max();
      A b = std::numeric_limits&lt;A&gt;::max();
  
      std::cout &lt;&lt; a.x &lt;&lt; "\n" &lt;&lt; b.x;
      // your code goes here
      return 0;
  }
  </code></pre>