Utils: Add std::expected implementation

Adds a std::expected implementation that is compatible with >= C++11.

FilePath::fileContents and FilePath::writeFileContents as well as
FilePath::copyFile are changed to return std::expected.

A couple of macros have been added to aid in using the expected types.

An auto test was added showing how to use the library.

Change-Id: Ibe3aecfc1029a0cf13b45bf5184ff03a04a2393b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marcus Tillmanns
2022-11-24 08:52:47 +01:00
parent 13c7283c0e
commit eca7044361
35 changed files with 2986 additions and 265 deletions

View File

@@ -16,6 +16,7 @@
#include <texteditor/texteditorconstants.h>
#include <texteditor/fontsettings.h>
#include <utils/expected.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/runextensions.h>
@@ -98,8 +99,10 @@ ExtraCompiler::ExtraCompiler(const Project *project, const FilePath &source,
if (!d->compileTime.isValid() || d->compileTime > lastModified)
d->compileTime = lastModified;
if (const std::optional<QByteArray> contents = target.fileContents())
setContent(target, *contents);
const expected_str<QByteArray> contents = target.fileContents();
QTC_ASSERT_EXPECTED(contents, return);
setContent(target, *contents);
}
}
@@ -169,10 +172,11 @@ void ExtraCompiler::onTargetsBuilt(Project *project)
if (d->compileTime >= generateTime)
return;
if (const std::optional<QByteArray> contents = target.fileContents()) {
d->compileTime = generateTime;
setContent(target, *contents);
}
const expected_str<QByteArray> contents = target.fileContents();
QTC_ASSERT_EXPECTED(contents, return);
d->compileTime = generateTime;
setContent(target, *contents);
}
});
}