title: How to validate input parameters in C++ constructor?
body: <p>Following example shows the crux of the problem. I need to initialize const members of a class. This can only be done in the initializer-list and not in constructor body. I want to assert or throw an error if input to the constructor is invalid, that is, if the vector size is less than 3.</p>
  
  <pre><code>class A {
   // In following constructor, how do we make sure if params.size()
   // is at least 3.
   A(const std::vector&lt;int&gt;&amp; params):
    x(params[0]), y(params[1]), z(params[2]) {}
  private:
    const int x;
    const int y;
    const int z;
  };
  </code></pre>
  
  <p>Please advise how to achieve this in Modern C++ (11 and later)</p>