dimanche 31 mai 2015

C++ how to generate all the permutations of function overloads?

Lets say I have classes Date and classes Year, Month and Day.

struct Date {
  Date(Year year, Month month, Day day) : d(day), m(month), y(year) {};
  Date(Month month, Day day, Year year) : d(day), m(month), y(year) {};
  Date(Day day, Month month, Year year) : d(day), m(month), y(year) {};
  Date(Day day, Year year, Month month) : d(day), m(month), y(year) {};
  ...
  ...

  private:
    Day d;
    Month m;
    Year y;
}

This allows me not to have a specific layout of arguments for Date as I have a lot of overloadings.

Am I able to generate all the permutations/overloadings automatically?

Just to be clear:

  • Permutations are only of argument layout, nothing about them should change as I know that would not be possible to automate.
  • All the generated overloadings should have the same code as only the layout of arguments changes not the logic itself.

Aucun commentaire:

Enregistrer un commentaire