You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replacing the abuse of the preprocossor in formula.cpp with templates
As stated in the developper guide, the whole preprocessor magic could be replaced by template (magic).
First tests successfull
For a first try, I replaced the original simple mandelbrot formula by a template construct, where calc is a simple
function template parametrized by a formula template.
This would be the base to rewrite the whole bunch of formulas, so for each formula
there would be a template with plugins for the calc() template.
My first version for the mandelbrot compiles successfully, and has the same timing
as the original preprocessor based one. (In fact it is slightly faster (1-2%), I have no Idea why
as it does the same calculations. )
Important Question
Has anybody else started, or planned to port the formulas to templates?
(Just to avoid unnecessary double work...)
Next steps
If there is nothing speaking against me to port the Formulas to templates
(Nobody else already works on it, or future plans contradicts it)
I would do first extended tests to see if my templated Version of the mandelbrot Formula
works correct, refactor the whole thing to make it better structured and more readable (currently each define
just got a static member in the formula template) and has same or better timing
secondly implement smooth mandelbrot and other formulas for mandelbrot (PERI and JULIA)
If everything works for mandelbrot, i'd create the formulaplugin-templates for all the
other formulas.
For each Version i'd do tests against the original formulas, as obviusly, for the same input
the new and the old formula should deliver the same results...
Offer
Id like to port the whole thing to templates, if there is interest for it.
As a cannot work fulltime on it, it might take some time (months)
If nobody else already works on this, and there are some positive
responses to this issue, I will go on with it.
I'd also like it, if somebody where willing to look over the
resulting template constructs to find the best structure
Open Question
For which C++ standard should the whole thing work?
(I used if constexpr () for some code, which requires c++17,
but it could be replaced by partial template specialization
resulting in more code duplicates or complexer templates)
Result
Two (configurable) versions of the formula (the old one using defines for older
compilers not suppporting templates as required)
and the new template based variant.
As it might be cumbersome to have two versions of the formulas it might be a good
idea to freeze the preprocessor variant and mark it deprecated...
The text was updated successfully, but these errors were encountered:
iaoesch
changed the title
Offer to port preprocessor abuse in formulas.cpp / docaolc.h to c++ templates
Offer to port preprocessor abuse in formulas.cpp / docalc.h to c++ templates
Feb 1, 2025
Replacing the abuse of the preprocossor in formula.cpp with templates
As stated in the developper guide, the whole preprocessor magic could be replaced by template (magic).
First tests successfull
For a first try, I replaced the original simple mandelbrot formula by a template construct, where calc is a simple
function template parametrized by a formula template.
This would be the base to rewrite the whole bunch of formulas, so for each formula
there would be a template with plugins for the calc() template.
My first version for the mandelbrot compiles successfully, and has the same timing
as the original preprocessor based one. (In fact it is slightly faster (1-2%), I have no Idea why
as it does the same calculations. )
Important Question
Has anybody else started, or planned to port the formulas to templates?
(Just to avoid unnecessary double work...)
Next steps
If there is nothing speaking against me to port the Formulas to templates
(Nobody else already works on it, or future plans contradicts it)
I would do first extended tests to see if my templated Version of the mandelbrot Formula
works correct, refactor the whole thing to make it better structured and more readable (currently each define
just got a static member in the formula template) and has same or better timing
secondly implement smooth mandelbrot and other formulas for mandelbrot (PERI and JULIA)
If everything works for mandelbrot, i'd create the formulaplugin-templates for all the
other formulas.
For each Version i'd do tests against the original formulas, as obviusly, for the same input
the new and the old formula should deliver the same results...
Offer
Id like to port the whole thing to templates, if there is interest for it.
As a cannot work fulltime on it, it might take some time (months)
If nobody else already works on this, and there are some positive
responses to this issue, I will go on with it.
I'd also like it, if somebody where willing to look over the
resulting template constructs to find the best structure
Open Question
For which C++ standard should the whole thing work?
(I used if constexpr () for some code, which requires c++17,
but it could be replaced by partial template specialization
resulting in more code duplicates or complexer templates)
Result
Two (configurable) versions of the formula (the old one using defines for older
compilers not suppporting templates as required)
and the new template based variant.
As it might be cumbersome to have two versions of the formulas it might be a good
idea to freeze the preprocessor variant and mark it deprecated...
The text was updated successfully, but these errors were encountered: