Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
q20memory.h
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
// Qt-Security score:significant reason:default
5
6
#
ifndef
Q20MEMORY_H
7
#
define
Q20MEMORY_H
8
9
#
include
<
QtCore
/
qtconfigmacros
.
h
>
10
11
#
include
<
QtCore
/
q17memory
.
h
>
12
13
#
include
<
QtCore
/
q20type_traits
.
h
>
14
#
include
<
utility
>
15
16
//
17
// W A R N I N G
18
// -------------
19
//
20
// This file is not part of the Qt API. Types and functions defined in this
21
// file can reliably be replaced by their std counterparts, once available.
22
// You may use these definitions in your own code, but be aware that we
23
// will remove them once Qt depends on the C++ version that supports
24
// them in namespace std. There will be NO deprecation warning, the
25
// definitions will JUST go away.
26
//
27
// If you can't agree to these terms, don't use these definitions!
28
//
29
// We mean it.
30
//
31
32
QT_BEGIN_NAMESPACE
33
34
// like std::construct_at (but not whitelisted for constexpr)
35
namespace
q20
{
36
#
ifdef
__cpp_lib_constexpr_dynamic_alloc
37
using
std
::
construct_at
;
38
#
else
39
template
<
typename
T,
40
typename
... Args,
41
typename
Enable =
std
::
void_t
<
decltype
(::
new
(
std
::
declval
<
void
*>())
T
(
std
::
declval
<
Args
>()...))> >
42
T *
construct_at
(T *ptr, Args && ... args)
43
{
44
return
::
new
(
const_cast
<
void
*>(
static_cast
<
const
volatile
void
*>(ptr)))
45
T(
std
::forward<Args>(args)...);
46
}
47
#
endif
// __cpp_lib_constexpr_dynamic_alloc
48
}
// namespace q20
49
50
// like std::make_unique_for_overwrite (excl. C++23-added constexpr)
51
namespace
q20
{
52
#
ifdef
__cpp_lib_smart_ptr_for_overwrite
53
using
std
::
make_unique_for_overwrite
;
54
#
else
55
// https://eel.is/c++draft/unique.ptr.create#6
56
template
<
typename
T
>
57
std
::
enable_if_t
<!
std
::
is_array_v
<
T
>,
std
::
unique_ptr
<
T
>>
58
make_unique_for_overwrite
()
59
// https://eel.is/c++draft/unique.ptr.create#7
60
{
return
std
::
unique_ptr
<
T
>(
new
T
); }
61
62
// https://eel.is/c++draft/unique.ptr.create#8
63
template
<
typename
T
>
64
std
::
enable_if_t
<
q20
::
is_unbounded_array_v
<
T
>,
std
::
unique_ptr
<
T
>>
65
make_unique_for_overwrite
(
std
::
size_t
n
)
66
// https://eel.is/c++draft/unique.ptr.create#9
67
{
return
std
::
unique_ptr
<
T
>(
new
std
::
remove_extent_t
<
T
>[
n
]); }
68
69
// https://eel.is/c++draft/unique.ptr.create#10
70
template
<
typename
T
,
typename
...
Args
>
71
std
::
enable_if_t
<
q20
::
is_bounded_array_v
<
T
>>
72
make_unique_for_overwrite
(
Args
&&...) =
delete
;
73
74
#
endif
// __cpp_lib_smart_ptr_for_overwrite
75
}
// namespace q20
76
77
namespace
q20
{
78
// like std::to_address
79
#
ifdef
__cpp_lib_to_address
80
using
std
::
to_address
;
81
#
else
82
// http://eel.is/c++draft/pointer.conversion
83
template
<
typename
T>
84
constexpr
T *
to_address
(T *p)
noexcept
{
85
// http://eel.is/c++draft/pointer.conversion#1:
86
// Mandates: T is not a function type.
87
static_assert
(!
std
::is_function_v<T>,
"to_address must not be used on function types"
);
88
return
p;
89
}
90
91
template
<
typename
Ptr,
typename
std::enable_if_t<!std::is_pointer_v<Ptr>,
bool
> =
true
>
92
constexpr
auto
to_address
(
const
Ptr &ptr)
noexcept
;
// fwd declared
93
94
namespace
detail
{
95
// http://eel.is/c++draft/pointer.conversion#3
96
template
<
typename
Ptr,
typename
=
void
>
97
struct
to_address_helper
{
98
static
constexpr
auto
get
(
const
Ptr &ptr)
noexcept
99
{
return
q20
::to_address(ptr.operator->()); }
100
};
101
template
<
typename
Ptr
>
102
struct
to_address_helper
<
Ptr
,
std
::
void_t
<
103
decltype
(
std
::
pointer_traits
<
Ptr
>::
to_address
(
std
::
declval
<
const
Ptr
&>()))
104
>>
105
{
106
static
constexpr
auto
get
(
const
Ptr
&
ptr
)
noexcept
107
{
return
std
::
pointer_traits
<
Ptr
>::
to_address
(
ptr
); }
108
};
109
}
// namespace detail
110
111
template
<
typename
Ptr,
typename
std
::
enable_if_t
<!
std
::
is_pointer_v
<
Ptr
>,
bool
>>
112
constexpr
auto
to_address
(
const
Ptr &ptr)
noexcept
113
{
return
detail::to_address_helper<Ptr>::get(ptr); }
114
115
#
endif
// __cpp_lib_to_address
116
}
// namespace q20
117
118
QT_END_NAMESPACE
119
120
#
endif
/* Q20MEMORY_H */
q20::detail
Definition
q20bit.h:51
q20
Definition
qnumeric.cpp:467
q20::to_address
constexpr T * to_address(T *p) noexcept
Definition
q20memory.h:84
q20::construct_at
T * construct_at(T *ptr, Args &&... args)
Definition
q20memory.h:42
q20::to_address
constexpr auto to_address(const Ptr &ptr) noexcept
Definition
q20memory.h:112
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
retrieveLabel
static QString retrieveLabel(const QStorageInfoPrivate &d, int fd, quint64 deviceId)
Definition
qstorageinfo_linux.cpp:390
MountId
static constexpr short MountId
Definition
qstorageinfo_linux.cpp:111
retrieveDeviceId
static quint64 retrieveDeviceId(const QByteArray &device, quint64 deviceId=0)
Definition
qstorageinfo_linux.cpp:327
MountInfoPath
static const char MountInfoPath[]
Definition
qstorageinfo_linux.cpp:48
MountPoint
static constexpr short MountPoint
Definition
qstorageinfo_linux.cpp:115
MountSource
static constexpr short MountSource
Definition
qstorageinfo_linux.cpp:120
FieldCount
static constexpr short FieldCount
Definition
qstorageinfo_linux.cpp:122
mountIdForPath
static quint64 mountIdForPath(int fd)
Definition
qstorageinfo_linux.cpp:313
MountOptions
static constexpr short MountOptions
Definition
qstorageinfo_linux.cpp:116
doParseMountInfo
std::vector< MountInfo > doParseMountInfo(const QByteArray &mountinfo, FilterMountInfo filter)
Definition
qstorageinfo_linux.cpp:170
FsType
static constexpr short FsType
Definition
qstorageinfo_linux.cpp:119
deviceNumber
static std::optional< dev_t > deviceNumber(QByteArrayView devno)
Definition
qstorageinfo_linux.cpp:50
retrieveLabelViaIoctl
static std::optional< QString > retrieveLabelViaIoctl(int fd)
Definition
qstorageinfo_linux.cpp:375
FS_IOC_GETFSLABEL
#define FS_IOC_GETFSLABEL
Definition
qstorageinfo_linux.cpp:28
DevNo
static constexpr short DevNo
Definition
qstorageinfo_linux.cpp:113
ST_RDONLY
#define ST_RDONLY
Definition
qstorageinfo_linux.cpp:33
parseMangledPath
static QByteArray parseMangledPath(QByteArrayView path)
Definition
qstorageinfo_linux.cpp:72
SuperOptions
static constexpr short SuperOptions
Definition
qstorageinfo_linux.cpp:121
devicesByLabel
static QDirListing devicesByLabel()
Definition
qstorageinfo_linux.cpp:351
FsRoot
static constexpr short FsRoot
Definition
qstorageinfo_linux.cpp:114
parseMountInfo
static std::vector< MountInfo > parseMountInfo(FilterMountInfo filter=FilterMountInfo::All)
Definition
qstorageinfo_linux.cpp:421
retrieveLabels
static auto retrieveLabels()
Definition
qstorageinfo_linux.cpp:358
decodeFsEncString
static QString decodeFsEncString(QString decoded)
Definition
qstorageinfo_linux.cpp:270
tokenizeLine
static void tokenizeLine(std::array< QByteArrayView, FieldCount > &fields, QByteArrayView line)
Definition
qstorageinfo_linux.cpp:126
deviceIdForPath
static dev_t deviceIdForPath(const QString &device)
Definition
qstorageinfo_linux.cpp:305
FSLABEL_MAX
#define FSLABEL_MAX
Definition
qstorageinfo_linux.cpp:25
doParseMountInfo
static std::vector< MountInfo > doParseMountInfo(const QByteArray &mountinfo, FilterMountInfo filter=FilterMountInfo::All)
Definition
qstorageinfo_linux.cpp:170
FilterMountInfo
FilterMountInfo
Definition
qstorageinfo_linux_p.h:34
FilterMountInfo::All
@ All
Definition
qstorageinfo_linux_p.h:35
FilterMountInfo::Filtered
@ Filtered
Definition
qstorageinfo_linux_p.h:36
q20::detail::to_address_helper
Definition
q20memory.h:97
q20::detail::to_address_helper::get
static constexpr auto get(const Ptr &ptr) noexcept
Definition
q20memory.h:98
statx
Definition
qfilesystemengine_unix.cpp:93
qtbase
src
corelib
global
q20memory.h
Generated on
for Qt by
1.18.0