Krita Source Code Documentation
Loading...
Searching...
No Matches
KisCppQuirks.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef KISCPPQUIRKS_H
7#define KISCPPQUIRKS_H
8
9#include <type_traits>
10#include <optional>
11#include <version>
12#include <QDebug>
13
14namespace std {
15
16template <bool is_const, class T>
18{
19 using type = std::conditional_t<is_const, std::add_const_t<T>, T>;
20};
21
22template <bool is_const, class T>
24
30template <typename Src, typename Dst>
31struct copy_const {
32 using type = add_const_if_t<std::is_const_v<Src>, std::remove_const_t<Dst>>;
33};
34
35template <typename Src, typename Dst>
37
38} // namespace std
39
40template <typename T>
41[[maybe_unused]]
42QDebug operator<<(QDebug dbg, const std::optional<T> &t)
43{
44
45 if (t) {
46 dbg.nospace() << "std::optional(" << *t << ")";
47 } else {
48 dbg.nospace() << "std::optional(nullopt)";
49 }
50
51 return dbg.space();
52}
53
54
55#endif // KISCPPQUIRKS_H
QDebug operator<<(QDebug dbg, const std::optional< T > &t)
typename copy_const< Src, Dst >::type copy_const_t
typename add_const_if< is_const, T >::type add_const_if_t
std::conditional_t< is_const, std::add_const_t< T >, T > type
add_const_if_t< std::is_const_v< Src >, std::remove_const_t< Dst > > type