std vector, QVector and fields..
-
@JonB it is hypothetical, because I'm pretty sure setupUi is not constexpr
but as example, take this compiletime calculation of fibonacci
constexpr int64_t fibonacci(const int64_t n) { return n < 1 ? -1 : (n == 1 || n == 2 ? 1 : fibonacci(n - 1) + fibonacci(n - 2)); } int main (int argc, char *argv[]) { constexpr auto evaled = fibonacci(25); return evaled; }
actually had to modify the example to force the compiletime evaluation , a little bit finicky the whole system (still)
@J-Hilk
OK, yes, I know about turning the C++ compiler into an interpreter withconstexpr
:) But thatfibonacci
function is self-contained. Compiler is not going to be able to execute anything likeconstexpr QObject::findChildren<QCheckBox *>
, it's runtime-only.Purely BTW. I'm not a great programmer (nor mathematician), so while I develop my code I have a go at:
constexpr int64_t fibonacci(const int64_t n) { int64_t result = 0; while (n > 0) result += n; return result; }
Now I compile my code. Does the compilation simply hang??
-
@J-Hilk
OK, yes, I know about turning the C++ compiler into an interpreter withconstexpr
:) But thatfibonacci
function is self-contained. Compiler is not going to be able to execute anything likeconstexpr QObject::findChildren<QCheckBox *>
, it's runtime-only.Purely BTW. I'm not a great programmer (nor mathematician), so while I develop my code I have a go at:
constexpr int64_t fibonacci(const int64_t n) { int64_t result = 0; while (n > 0) result += n; return result; }
Now I compile my code. Does the compilation simply hang??
@JonB said in std vector, QVector and fields..:
Now I compile my code. Does the compilation simply hang??
No, because you're not calling it :-)
And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-) -
@JonB said in std vector, QVector and fields..:
Now I compile my code. Does the compilation simply hang??
No, because you're not calling it :-)
And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-)@jsulm
Oh yes I am! In @J-Hilk's code (at least originally) hismain()
callsfibonacci(10)
, so assume that, and then tell me what happens while I sit waiting for the compilation to finish?And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-)
I think you should look at the code again... :)
-
@jsulm
Oh yes I am! In @J-Hilk's code (at least originally) hismain()
callsfibonacci(10)
, so assume that, and then tell me what happens while I sit waiting for the compilation to finish?And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-)
I think you should look at the code again... :)
-
@jsulm
Oh yes I am! In @J-Hilk's code (at least originally) hismain()
callsfibonacci(10)
, so assume that, and then tell me what happens while I sit waiting for the compilation to finish?And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-)
I think you should look at the code again... :)
-
You should try :-)
I'm terrified of seizing up my Linux VM :) It already does that if I accidentally debug from Creator when inside a
QComboBox
clicked slot, and I have to hard-switch-off the whole VM... :(main.cpp:158:18: error: expression is not an integral constant expression main.cpp:152:13: note: constexpr evaluation hit maximum step limit; possible infinite loop? main.cpp:158:18: note: in call to 'fibonacci(25)'
smart things these compilers
-
@JonB Add at least a function call to your calculation, then you get an stack overflow(eventually)
@J-Hilk said in std vector, QVector and fields..:
@JonB Add at least a function call to your calculation, then you get an stack overflow(eventually)
But I don't want a stackoverflow to terminate! I want to know whether the compiler sits there forever! Which is why I wrote as I did.
OK, I'm off to try....
-
main.cpp:158:18: error: expression is not an integral constant expression main.cpp:152:13: note: constexpr evaluation hit maximum step limit; possible infinite loop? main.cpp:158:18: note: in call to 'fibonacci(25)'
smart things these compilers
@J-Hilk said in std vector, QVector and fields..:
note: constexpr evaluation hit maximum step limit; possible infinite loop?
Ah ha! So..... this C++
constexpr
has what "maximum step limit`? Where is that in the spec? :) -
@J-Hilk said in std vector, QVector and fields..:
note: constexpr evaluation hit maximum step limit; possible infinite loop?
Ah ha! So..... this C++
constexpr
has what "maximum step limit`? Where is that in the spec? :)