title: C++ calculate and sort vector at compile time
body: <p>I have a <code>class A</code> that has a <code>std::vector&lt;int&gt;</code> as attribute.
  <code>A</code> needs to fill this vector when an instance of <code>A</code> is created.
  The calculation can take some time and I would like to know if:</p>
  
  <ol>
  <li>it can be done at compile time.  </li>
  <li>the vector can be sorted at compile time as well</li>
  </ol>
  
  <p>I am not familiar with metaprogramming and I didn't find a way to do it for now. It's not an OS-specific question.</p>
  
  <p>Here is the <code>A.cpp</code> file :</p>
  
  <pre><code>#include "A.h"
  #define SIZEV 100
  
  A::A()
  {
      fillVector();
  }
  
  void A::fillVector()
  {
      // m_vector is an attribute of class "A"
      // EXPECTATION 1 : fill the vector with the following calculation at compile time
  
      const int a=5;
      const int b=7;
      const int c=9;
  
      for(int i=0;i&lt;SIZEV;i++){
          for(int j=0;j&lt;SIZEV;j++){
              for(int k=0;k&lt;SIZEV;k++){
                  this-&gt;m_vector.push_back(a*i+b*j+c*k);
              }
          }
      }
  
      // EXPECTATION 2 : sort the vector as compile time 
  }
  
  std::vector&lt;int&gt; A::getVector() const
  {
      return m_vector;
  }
  
  void A::setVector(const std::vector&lt;int&gt; &amp;vector)
  {
      m_vector = vector;
  }
  </code></pre>
  
  <p>and the <code>main.cpp</code> (Qt app but doesn't matter):</p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  #include "A.h"
  
  int main(int argc, char *argv[])
  {
      QCoreApplication app(argc, argv);
  
      A a;
      auto vec = a.getVector();
  
      // use vec, etc ...
  
      return app.exec();
  }
  </code></pre>