title: Function with variadic arguments of a custom struct type
body: <p>I come from a Swift background and, though I know some C as well, this is my first time writing C++ code.</p>
  
  <p>In Swift it is possible to write a function that takes any number of arguments:</p>
  
  <pre><code>func foo(bar: String...) {
      // ...
  }
  </code></pre>
  
  <p>and <code>bar</code> can be of any type (String, Bool, Struct, Enum, etc).</p>
  
  <p>I was wondering if the same can be done in C++. So, ideally I would write:</p>
  
  <pre><code>struct X {
      string s;
      X(int);
      // ...
  }
  
  void foo(string s, ...) {
      // ...
  }
  
  foo("mystr", X(1), X(2), X(3));
  </code></pre>
  
  <p>and inside <code>foo</code> I would somehow be able to access the list of arguments, somewhat akin to a <code>printf</code> function.</p>
  
  <p>Right now I'm using a <code>vector&lt;X&gt;</code> as argument, since all the arguments have type X. However, that makes calling <code>foo</code> somewhat ugly, in my opinion:</p>
  
  <pre><code>foo("mystr", { X(1), X(2), X(3) });
  </code></pre>
  
  <p>Any solution I'm not seeing due to my strong lack of knowledge towards C++?</p>
  
  <hr>
  
  <p><strong>Edit:</strong>
  This is what I want done specifically inside <code>foo</code>:</p>
  
  <pre><code>string ssub(string s, vector&lt;X&gt; v) {
      int index, i = 0;
  
      while (1) {
          index = (int)s.find(SUB);
          if (index == string::npos) { break; }
          s.erase(index, string(SUB).size());
          s.insert(index, v[i].tostr());
          i++;
      }
  
      return s;
  }
  </code></pre>
  
  <p>Basically, as long as I'm given a way to sequentially access the arguments, all is good.</p>