Files
qt-creator/src/libs/utils/expected.h
Marco Bubke 77b2c82f05 Utils: Make CTAD work with std::unexpected
Aliases are not working with CTAD before C++ 20. Instead of aliasing
some types we simply importing the namespace tl into the namespace
Utils. This enables some not aliased things too.

Change-Id: Ic61a50bedbbf7253ecb5bb1f6dc0624dcc704aa0
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 8b2d7977ca)
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2023-05-16 14:38:12 +00:00

33 lines
952 B
C++

// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "qtcassert.h"
#include "../3rdparty/tl_expected/include/tl/expected.hpp"
namespace Utils {
using namespace tl;
template<class T>
using expected_str = tl::expected<T, QString>;
} // namespace Utils
//! If 'expected' has an error the error will be printed and the 'action' will be executed.
#define QTC_ASSERT_EXPECTED(expected, action) \
if (Q_LIKELY(expected)) { \
} else { \
::Utils::writeAssertLocation(QString("%1:%2: %3") \
.arg(__FILE__) \
.arg(__LINE__) \
.arg(expected.error()) \
.toUtf8() \
.data()); \
action; \
} \
do { \
} while (0)