c++ - Extending the compiler to evaluate "complicated" function (with known input values) at compile time, out of `constexpr` reach -


please take @ this example. trying use constexpr obtain compile time evaluation utterly difficult, if not impossible.

however, function called arguments known @ compile time. in theory, (in presence of optimization attribute?), compiler pause parsing, create small program function, compile it, run it, , result create char constant used in main program compilation.

i understand 1 of problem example cross compiling: run program compiler if compiler can build program can run on machine building. doesn't seem impossible overcome.

there no doubt: not first 1 think it. tried search , found constexpr , template stuff. there plan implement such feature in compiler in future? feature rephrased as: give possibility write c++ program within c++ source compiler can compile , run upon request create constant.

the constexpr , template ways in c++ force compiler @ compile time. in many cases optimizer able figure out more complicated functions well. however, may inadvertely step away compiler's ``comfort zone'', e.g. through allocation and/or pointer arithmetic.

as marc glisse points out in comments, in concrete example using std::string rather native char* , due magic done within implementation of class, optimizer may lost.

that being said, may welcome c++14 relaxes requirements function constexpr. can declare local variables, have mutating objects , have basic control flow structures. can manipulate raw strings too.

https://isocpp.org/wiki/faq/cpp14-language#extended-constexpr


looking @ broader picture, there ongoing research bring staging programming languages. staging idea of program being partially evaluated through explicit code constructs, allowing complex functions executed @ compile time. example approaches problem, taking different angles:

note neither of tries in c++ though.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -