diff options
author | Eike Ziller <eike.ziller@qt.io> | 2016-07-13 11:19:24 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2017-06-16 12:19:27 +0000 |
commit | 93f4fb771fbfcb8499601b497a4b2b436d872c1d (patch) | |
tree | 2778fa04bc9a160ab4a639910627065cd408f9ef /src/libs/utils | |
parent | 42580c7d0ca703f216bcb19e12259b1022d8b423 (diff) | |
download | qt-creator-93f4fb771fbfcb8499601b497a4b2b436d872c1d.tar.gz |
Add std::experimental::optional as Utils::optional
Uses the reference implementation of the proposal, which later
can be replaced by the std lib implementation depending on compiler
and used C++ version.
Change-Id: I23f2f8077f4cb26c3d9a403b1ce438b6cdb163f2
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/libs/utils')
-rw-r--r-- | src/libs/utils/optional.h | 58 | ||||
-rw-r--r-- | src/libs/utils/utils-lib.pri | 4 | ||||
-rw-r--r-- | src/libs/utils/utils.qbs | 2 |
3 files changed, 63 insertions, 1 deletions
diff --git a/src/libs/utils/optional.h b/src/libs/utils/optional.h new file mode 100644 index 0000000000..1960297de4 --- /dev/null +++ b/src/libs/utils/optional.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +/* + optional<T> + make_optional(t) + + See std(::experimental)::optional. +*/ + +// TODO: replace by #include <(experimental/)optional> depending on compiler and C++ version +#include <3rdparty/optional/optional.hpp> + +namespace Utils { + +// --> Utils::optional +using std::experimental::optional; +// --> Utils::nullopt +using std::experimental::nullopt; + +// TODO: make_optional is a copy, since there is no sensible way to import functions in C++ +template <class T> +constexpr optional<typename std::decay<T>::type> make_optional(T&& v) +{ + return optional<typename std::decay<T>::type>(std::experimental::constexpr_forward<T>(v)); +} + +template <class X> +constexpr optional<X&> make_optional(std::reference_wrapper<X> v) +{ + return optional<X&>(v.get()); +} + +} // Utils diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index ef988e76e0..a20a41d159 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -237,7 +237,9 @@ HEADERS += \ $$PWD/smallstringio.h \ $$PWD/guard.h \ $$PWD/asconst.h \ - $$PWD/smallstringfwd.h + $$PWD/smallstringfwd.h \ + $$PWD/optional.h \ + $$PWD/../3rdparty/optional/optional.hpp FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 651135d7fa..03a47ae060 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -142,6 +142,8 @@ Project { "newclasswidget.cpp", "newclasswidget.h", "newclasswidget.ui", + "optional.h", + "../3rdparty/optional/optional.hpp", "osspecificaspects.h", "outputformat.h", "outputformatter.cpp", |