On Monday, 21 September 2020 22:55:16 PDT Lars Knoll wrote: > I do not want to simply return an int, as the risk that people ignore the > Unordered state it too big with that. So the other choice would be to add > an enum in the Qt namespace (as I need this for QMetaType as well, which > currently has a std::optional<int> compare()).
For internal APIs, please return just a plain int. For public ones, either call the internal or please use std::optional<qsizetype>. Code generation is slightly better. Compare the Clang panes at qsizetype - https://gcc.godbolt.org/z/5bTbq6 int - https://gcc.godbolt.org/z/b6jn8s The other three compilers just show how using std::optional is worse than an int: both GCC and ICC currently unnecessarily spill to the stack (you can avoid the spillage with std::optional<signed char>). MSVC always returns non- primitives by implicit reference, so a memory access is always present. All the memory accesses go away if you call an internal function: https://gcc.godbolt.org/z/rYde7c -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel DPG Cloud Engineering _______________________________________________ Development mailing list [email protected] https://lists.qt-project.org/listinfo/development
