Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer to port preprocessor abuse in formulas.cpp / docalc.h to c++ templates #262

Open
iaoesch opened this issue Feb 1, 2025 · 1 comment

Comments

@iaoesch
Copy link

iaoesch commented 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...

@iaoesch 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
@kovzol
Copy link
Contributor

kovzol commented Feb 1, 2025

Great idea, please go ahead with it.
I think it's safe to use c++17 since Qt also requires that, according to https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/global/qcompilerdetection.h#n1298.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants