-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Description
Hi
C++ constexpr is really a killer feature, allowing to create small byte code at compile time for everything that is deterministic, while allowing the same code to be used on what isn't deterministic.
In a way it's better than a template.
as template, and inline, they have the issue to be "recompiled" in each module they are used, this can increase the compile time and also make it difficult to share it in a library.
The compiler can also choose not to inline the function.
pre-compiled header don't match my needs
so I wonder if there is some compile option flag that could allow me to create a library (shared and static) providing my constexpr functions (aside my non constexpr functions) and pass it as an argument when compiling my modules
- the constexpr function in library is assumed to be uptodate with the source in header (this is the role of the make system) once the library arg is provided.
- if the function is used in module, and constexpr can be evaluated at compile time, then the compiler call the library function and use the result
- if the function is used in module, and constexpr can't be evaluated at compile time
1. if the function is inline-able : the library code is copied in place, maybe modified to remove the function call overhead (argument creation and return value removal), don't know if there is a way in library to create functions that can't be called, but just stored, so without the overhead, in which case, the library act like a compiler cache, but not sure if it's something that is interesting or if the function should be usable and "dlopen-usable"
2. if the function is not inline-able : the symbol resolution is performed at link time as a regular library function
this will save lot of time in compilation, while taking full advantage of constexpr code optimization (size and speed)
thanks and regards