Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Is there any design error by which I need the template type of the solution in every other class?

That dependency is quite common in Genetic Algorithm / Genetic Programming frameworks and it isn't per se a design error.

There are two reasons because of which your code looks that way:

Consider that template template parameterstemplate template parameters (and good default values) could be a way to lower the perceived complexity of using the library and help with the coordination of the types among the various classes.

Is there any design error by which I need the template type of the solution in every other class?

That dependency is quite common in Genetic Algorithm / Genetic Programming frameworks and it isn't per se a design error.

There are two reasons because of which your code looks that way:

  • classes that interact with Solutions often need to store them (trials, best so far...) or classes depending on them.

    Type erasure (e.g. boost::any) doesn't mix well and boost::variant introduces unwanted constraints.

  • member function templates cannot be declared virtual but virtual methods are often a necessity (in your snippet applyOp, exploreNg...). In contrast ordinary members of class templates can be virtual and this is a further "incentive".

Consider that template template parameters (and good default values) could be a way to lower the perceived complexity of using the library and help with the coordination of the types among the various classes.

Is there any design error by which I need the template type of the solution in every other class?

That dependency is quite common in Genetic Algorithm / Genetic Programming frameworks and it isn't per se a design error.

There are two reasons because of which your code looks that way:

  • classes that interact with Solutions often need to store them (trials, best so far...) or classes depending on them.

    Type erasure (e.g. boost::any) doesn't mix well and boost::variant introduces unwanted constraints.

  • member function templates cannot be declared virtual but virtual methods are often a necessity (in your snippet applyOp, exploreNg...). In contrast ordinary members of class templates can be virtual and this is a further "incentive".

Consider that template template parameters (and good default values) could be a way to lower the perceived complexity of using the library and help with the coordination of the types among the various classes.

Source Link
manlio
  • 4.2k
  • 3
  • 26
  • 37

Is there any design error by which I need the template type of the solution in every other class?

That dependency is quite common in Genetic Algorithm / Genetic Programming frameworks and it isn't per se a design error.

There are two reasons because of which your code looks that way:

  • classes that interact with Solutions often need to store them (trials, best so far...) or classes depending on them.

    Type erasure (e.g. boost::any) doesn't mix well and boost::variant introduces unwanted constraints.

  • member function templates cannot be declared virtual but virtual methods are often a necessity (in your snippet applyOp, exploreNg...). In contrast ordinary members of class templates can be virtual and this is a further "incentive".

Consider that template template parameters (and good default values) could be a way to lower the perceived complexity of using the library and help with the coordination of the types among the various classes.