Q:

would it be possible to initialize an object of a certain kind by passing an initializer list to a generator function

I have a factory class with a function to generate a certain type of objects. However, at present moment, this function takes an explicit set of parameters before instantiating an object and returning it back in the main scope of the program. These objects are generated using random numbers as its parameters. At some point, I will overload the constructor of the class of which objects I create to take more or less parameters. Therefore to avoid creating many functions in my factory class generating the same object with varying set of parameters, I thought I could use an initialization list. I have tried to implement this solution but I failed miserably. Could someone please enlighten me what do I do wrong? Or perhaps point me in the right direction :)
Below is a basic example of what I am trying to do
#include <iostream>
#include <initializer_list>

// iostream
using std::cout;
using std::endl;

// initializer list
using std::initializer_list;

// Class of which type I want to generate objects;
class Subject{
private:
  double x;
  double y;
public:
  Subject(const double x, const double y); // <-- This may vary in parameter set!
  void print();
};

// Class which is responsible for generating objects of type specified above;
class Generator{
public:
  Generator();
  Subject generate(initializer_list<double> params);
};

// Subject Member Implementation
Subject::Subject(const double x, const double y):x(x), y(y){}

void Subject::print(){
  std::cout << "x: " << x << "y: " << y << std::endl;
}

// Generator Member Implementation
Generator::Generator(){}

Subject Generator::generate(initializer_list<double> params){
  Subject subject = params;

  return subject;
}

// Main Body
int main(){
  Generator generator;
  double params[2] = {.1,.2}; // <-- arbitrary set of parameter(s)

  Subject subject = generator.generate({params}); // <-- object cration;

  subject.print();
}

A:

It could be made to work, but the types and implicit types must be considered.
Here are some examples of what would work vs. what would not work:
#include <initializer_list>
#include <iterator> 

void f(std::initializer_list<int> il) {}

int main()
{
    int parameters[4]{1, 2, 3, 4};
    auto test1 = {parameters};  // parameters decays into an int*, so we get an initializer_list of int*s (single pointer in this case)

    // named parameter causes problems
    //f(parameters);    // doesn't compile, can't convert array to initializer_list
    //f({parameters});  // doesn't compile, initializer_list types are different
    //f({std::begin(parameters), std::end(parameters)}); // doesn't compile, considered as list of pointers

    // this works on MSVC, but is probably not standard C++
    std::initializer_list<int> test2(std::begin(parameters), std::end(parameters)); // use constructor that accepts iterators
    f(std::initializer_list<int>(std::begin(parameters), std::end(parameters))); // ok
    f(test2);           // ok

    f({1, 2, 3, 4});    // ok, can construct parameter with this initializer
    f({});              // ok, for the same reason as above
}

