1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.core.pair;
15 extern(C++):
16
17 import qt.config;
18 import qt.helpers;
19
20 struct QPair(T1, T2)
21 {
22 alias first_type = T1;
23 alias second_type = T2;
24
25 /+this()
26 /+ noexcept((std::is_nothrow_default_constructible<T1>::value &&
27 std::is_nothrow_default_constructible<T2>::value)) +/
28 {
29 this.first = typeof(this.first)();
30 this.second = typeof(this.second)();
31 }+/
32 this(ref const(T1) t1, ref const(T2) t2)
33 /+ noexcept((std::is_nothrow_copy_constructible<T1>::value &&
34 std::is_nothrow_copy_constructible<T2>::value)) +/
35 {
36 this.first = t1;
37 this.second = t2;
38 }
39 // compiler-generated copy/move ctor/assignment operators are fine!
40
41 /+ template <typename TT1, typename TT2> +/
42 /+ QPair(const QPair<TT1, TT2> &p)
43 noexcept((std::is_nothrow_constructible<T1, TT1&>::value &&
44 std::is_nothrow_constructible<T2, TT2&>::value))
45 : first(p.first), second(p.second) {} +/
46 /+ template <typename TT1, typename TT2> +/
47 /+ QPair &operator=(const QPair<TT1, TT2> &p)
48 noexcept((std::is_nothrow_assignable<T1, TT1&>::value &&
49 std::is_nothrow_assignable<T2, TT2&>::value))
50 { first = p.first; second = p.second; return *this; } +/
51 /+ template <typename TT1, typename TT2> +/
52 /+ QPair(QPair<TT1, TT2> &&p)
53 noexcept((std::is_nothrow_constructible<T1, TT1>::value &&
54 std::is_nothrow_constructible<T2, TT2>::value))
55 // can't use std::move here as it's not constexpr in C++11:
56 : first(static_cast<TT1 &&>(p.first)), second(static_cast<TT2 &&>(p.second)) {} +/
57 /+ template <typename TT1, typename TT2> +/
58 /+ QPair &operator=(QPair<TT1, TT2> &&p)
59 noexcept((std::is_nothrow_assignable<T1, TT1>::value &&
60 std::is_nothrow_assignable<T2, TT2>::value))
61 { first = std::move(p.first); second = std::move(p.second); return *this; } +/
62
63 /+ void swap(QPair &other)
64 noexcept(noexcept(qSwap(other.first, other.first)) && noexcept(qSwap(other.second, other.second)))
65 {
66 // use qSwap() to pick up ADL swaps automatically:
67 qSwap(first, other.first);
68 qSwap(second, other.second);
69 } +/
70
71 T1 first;
72 T2 second;
73 }
74
75 /+ #if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
76 template<class T1, class T2>
77 QPair(T1, T2) -> QPair<T1, T2>;
78 #endif
79
80 template <typename T1, typename T2>
81 void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs) noexcept(noexcept(lhs.swap(rhs)))
82 { lhs.swap(rhs); }
83
84 // mark QPair<T1,T2> as complex/movable/primitive depending on the
85 // typeinfos of the constituents:
86 template<class T1, class T2>
87 class QTypeInfo<QPair<T1, T2> > : public QTypeInfoMerger<QPair<T1, T2>, T1, T2> {}; +/ // Q_DECLARE_TYPEINFO
88
89 /+pragma(inline, true) bool operator ==(T1, T2)(ref const(QPair!(T1, T2)) p1, ref const(QPair!(T1, T2)) p2)
90 /+ noexcept(noexcept(p1.first == p2.first && p1.second == p2.second)) +/
91 { return p1.first == p2.first && p1.second == p2.second; }+/
92
93 /+pragma(inline, true) bool operator !=(T1, T2)(ref const(QPair!(T1, T2)) p1, ref const(QPair!(T1, T2)) p2)
94 /+ noexcept(noexcept(!(p1 == p2))) +/
95 { return !(p1 == p2); }+/
96
97 /+pragma(inline, true) bool operator <(T1, T2)(ref const(QPair!(T1, T2)) p1, ref const(QPair!(T1, T2)) p2)
98 /+ noexcept(noexcept(p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second))) +/
99 {
100 return p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second);
101 }+/
102
103 /+pragma(inline, true) bool operator >(T1, T2)(ref const(QPair!(T1, T2)) p1, ref const(QPair!(T1, T2)) p2)
104 /+ noexcept(noexcept(p2 < p1)) +/
105 {
106 return p2 < p1;
107 }+/
108
109 /+pragma(inline, true) bool operator <=(T1, T2)(ref const(QPair!(T1, T2)) p1, ref const(QPair!(T1, T2)) p2)
110 /+ noexcept(noexcept(!(p2 < p1))) +/
111 {
112 return !(p2 < p1);
113 }+/
114
115 /+pragma(inline, true) bool operator >=(T1, T2)(ref const(QPair!(T1, T2)) p1, ref const(QPair!(T1, T2)) p2)
116 /+ noexcept(noexcept(!(p1 < p2))) +/
117 {
118 return !(p1 < p2);
119 }+/
120
121 QPair!(T1, T2) qMakePair(T1, T2)(ref const(T1) x, ref const(T2) y)
122 /+ noexcept(noexcept(QPair<T1, T2>(x, y))) +/
123 {
124 return QPair!(T1, T2)(x, y);
125 }
126