Is it not nice to share your knowledge why it is not possible? 😉 Is it because the meta type information could be created later? What about adding a constexpr version like: QMetaEnum::compileTimeFromType? Or do we wait for static reflections?
________________________________ From: Development <development-boun...@qt-project.org> on behalf of Thiago Macieira <thiago.macie...@intel.com> Sent: Monday, December 31, 2018 12:51:46 PM To: development@qt-project.org Subject: Re: [Development] Use QMetaEnum::keyCount() to initialise array On Sunday, 30 December 2018 17:43:21 -02 Tom Isaacson wrote: > Is it possible to use QMetaEnum::keyCount() to initialise an array? > Something like: > > const QMetaEnum metaEnum = QMetaEnum::fromType<MyArray>(); > int MyArray[metaEnum.keyCount()]; Yes. This should compile with GCC and Clang. It uses a C99 feature that is allowed in their C++ compilers known as Variable Length Array. But the code is non-standard and may not compile in other compilers. If you want to make it portable, use QVector, QVarLengthArray or std::vector. > I don't know how the Meta-Object Compiler creates this but surely it's > possible to change it to be constexpr? No, it's not. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center _______________________________________________ Development mailing list Development@qt-project.org https://lists.qt-project.org/listinfo/development
_______________________________________________ Development mailing list Development@qt-project.org https://lists.qt-project.org/listinfo/development