|
|
jonnin wrote: |
---|
make a little junk program that writes the C++ code to initialize it. |
|
|
|
|
Grime wrote: |
---|
I don't get it.. Whether the computation is exclusively marked as to be done at compile time or whether the assigning is left to be done at run-time, what is the difference? Both should do the same thing right? Both would produce assembly code that would say "allocate memory and put value so and so". Computations can be done at compile-time but you can't allocate and assign values at compile time. So what is the difference between a for-loop and using templates and constexpr? Do they at all even produce different results? Somebody pls enlighten me. 0_0 |
If it were an optimizing compiler, for OP the values would probably be evaluated compile time. |
Now instead, we are defining a template function. Template functions can be called at run-time too. So we're adding those 10 more lines of assembly which we were trying to avoid. |
Grime wrote: |
---|
How does the compiler know whether a constexpr or templates function is going to be used at runtime or not? |
Grime wrote: |
---|
Is it guaranteed by standard that the template function won't be generated if it's not required? |
|
|
|
|
|
|
Grime wrote: |
---|
So in that case the template for int is indeed generated for runtime use. |
Grime wrote: |
---|
Can we explicitly make a function that is used only for compile time and doesn't exist at run time? |
|
|