> How does that apply to Linux and other OSes? The problem there is that
> constexpr evaluation must still see the definitions. You cannot write, like in
> qfilesystemengine_unix.cpp:
>
> if constexpr (Qt::OS::isLinux) {
> if (renameat2(AT_FDCWD, srcPath, AT_FDCWD, tgtPath, RENAME_NOREPLACE) ==
> 0)
> return true;
> } else if constexpr (Qt:OS::isDarwin) {
> if (renameatx_np(AT_FDCWD, srcPath, AT_FDCWD, tgtPath, RENAME_EXCL) == 0)
> return true;
> }
depending on the code, one could utilize tag dispatching, so only then
overload declarations would require the preprocessor.
```
#ifdef LINUX
auto rename(auto src, auto target, Os::LinuxT) {
return renameat2(...);
}
#elif DARWIN
auto rename(auto src, auto target, Os::DarwinT) {
return renameatx_np(...);
}
#endif
auto rename(auto src, auto target)
{
return rename(src, target, Os::Current); // no ifdef
}
```
but yes, there's not much advantage over the preprocessor
> So I think there's little value in this new API: it can't be used for
> dispatching to functions or using constants or types that may not be defined,
> and it may lead to sloppy code that tests for the wrong thing.
>
> But not zero value. I could see a few uses here and there. So we still need
> to
> come up with a good API.
it is mainly useful for cases where no platform-specific APIs are
involved, but one still wants to do per-platform decisions.
--
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development