1/****************************************************************************
2**
3** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
4** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#if 0
42#pragma qt_sync_skip_header_check
43#pragma qt_sync_stop_processing
44#endif
45
46#ifndef QCONTAINERTOOLS_IMPL_H
47#define QCONTAINERTOOLS_IMPL_H
48
49#include <QtCore/qglobal.h>
50#include <iterator>
51
52#ifndef Q_QDOC
53
54QT_BEGIN_NAMESPACE
55
56namespace QtPrivate
57{
58template <typename Iterator>
59using IfIsInputIterator = typename std::enable_if<
60 std::is_convertible<typename std::iterator_traits<Iterator>::iterator_category, std::input_iterator_tag>::value,
61 bool>::type;
62
63template <typename Iterator>
64using IfIsForwardIterator = typename std::enable_if<
65 std::is_convertible<typename std::iterator_traits<Iterator>::iterator_category, std::forward_iterator_tag>::value,
66 bool>::type;
67
68template <typename Iterator>
69using IfIsNotForwardIterator = typename std::enable_if<
70 !std::is_convertible<typename std::iterator_traits<Iterator>::iterator_category, std::forward_iterator_tag>::value,
71 bool>::type;
72
73template <typename Container,
74 typename InputIterator,
75 IfIsNotForwardIterator<InputIterator> = true>
76void reserveIfForwardIterator(Container *, InputIterator, InputIterator)
77{
78}
79
80template <typename Container,
81 typename ForwardIterator,
82 IfIsForwardIterator<ForwardIterator> = true>
83void reserveIfForwardIterator(Container *c, ForwardIterator f, ForwardIterator l)
84{
85 c->reserve(static_cast<typename Container::size_type>(std::distance(f, l)));
86}
87
88// for detecting expression validity
89template <typename ... T>
90using void_t = void;
91
92template <typename Iterator, typename = void_t<>>
93struct AssociativeIteratorHasKeyAndValue : std::false_type
94{
95};
96
97template <typename Iterator>
98struct AssociativeIteratorHasKeyAndValue<
99 Iterator,
100 void_t<decltype(std::declval<Iterator &>().key()),
101 decltype(std::declval<Iterator &>().value())>
102 >
103 : std::true_type
104{
105};
106
107template <typename Iterator, typename = void_t<>, typename = void_t<>>
108struct AssociativeIteratorHasFirstAndSecond : std::false_type
109{
110};
111
112template <typename Iterator>
113struct AssociativeIteratorHasFirstAndSecond<
114 Iterator,
115 void_t<decltype(std::declval<Iterator &>()->first),
116 decltype(std::declval<Iterator &>()->second)>
117 >
118 : std::true_type
119{
120};
121
122template <typename Iterator>
123using IfAssociativeIteratorHasKeyAndValue =
124 typename std::enable_if<AssociativeIteratorHasKeyAndValue<Iterator>::value, bool>::type;
125
126template <typename Iterator>
127using IfAssociativeIteratorHasFirstAndSecond =
128 typename std::enable_if<AssociativeIteratorHasFirstAndSecond<Iterator>::value, bool>::type;
129
130} // namespace QtPrivate
131
132QT_END_NAMESPACE
133
134#endif // Q_QDOC
135
136#endif // QCONTAINERTOOLS_IMPL_H
137