title: How to prevent implicit conversion from int to unsigned int?
body: <p>Suppose you have this:</p>
  
  <pre><code>struct Foo {
      Foo(unsigned int x) : x(x) {}
      unsigned int x;
  };
  
  int main() {
      Foo f = Foo(-1);     // how to get a compiler error here?
      std::cout &lt;&lt; f.x &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p><strong>Is it possible to prevent the implicit conversion?</strong></p>
  
  <p>The only way I could think of is to explicilty provide a constructor that takes an <code>int</code> and generates some kind of runtime error if the <code>int</code> is negative, but it would be nicer if I could get a compiler error for this.</p>
  
  <p>I am almost sure, that there is a duplicate, but the closest I could find is <a href="https://stackoverflow.com/questions/5263267/why-does-c-allows-implicit-conversion-from-int-to-unsigned-int">this question</a> which rather asks why the implicit conversion is allowed. </p>
  
  <p>I am interested in both, C++11 and pre C++11 solutions, preferably one that would work in both.</p>