stdgpu/utility.h Source File

stdgpu/utility.h Source File#

stdgpu: stdgpu/utility.h Source File
stdgpu Latest
Efficient STL-like Data Structures on the GPU
utility.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Patrick Stotko
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef STDGPU_UTILITY_H
17#define STDGPU_UTILITY_H
18
28#include <type_traits>
29
30#include <stdgpu/platform.h>
31#include <stdgpu/type_traits.h>
32
33namespace stdgpu
34{
35
42template <typename T1, typename T2>
43struct pair
44{
45 using first_type = T1;
46 using second_type = T2;
51 ~pair() = default;
52
56 template <STDGPU_DETAIL_OVERLOAD_IF(std::is_default_constructible_v<T1>&& std::is_default_constructible_v<T2>)>
57 constexpr STDGPU_HOST_DEVICE
59
65 template <STDGPU_DETAIL_OVERLOAD_IF(std::is_copy_constructible_v<T1>&& std::is_copy_constructible_v<T2>)>
66 constexpr STDGPU_HOST_DEVICE
67 pair(const T1& x, const T2& y);
68
76 template <class U1 = T1,
77 class U2 = T2,
78 STDGPU_DETAIL_OVERLOAD_IF(std::is_constructible_v<T1, U1>&& std::is_constructible_v<T2, U2>)>
79 constexpr STDGPU_HOST_DEVICE
80 pair(U1&& x, U2&& y);
81
88 template <typename U1,
89 typename U2,
90 STDGPU_DETAIL_OVERLOAD_IF(std::is_constructible_v<T1, U1&>&& std::is_constructible_v<T2, U2&>)>
91 constexpr STDGPU_HOST_DEVICE
92 pair(pair<U1, U2>& p); // NOLINT(hicpp-explicit-conversions)
93
100 template <
101 typename U1,
102 typename U2,
103 STDGPU_DETAIL_OVERLOAD_IF(std::is_constructible_v<T1, const U1&>&& std::is_constructible_v<T2, const U2&>)>
104 constexpr STDGPU_HOST_DEVICE
105 pair(const pair<U1, U2>& p); // NOLINT(hicpp-explicit-conversions)
106
113 template <class U1,
114 class U2,
115 STDGPU_DETAIL_OVERLOAD_IF(std::is_constructible_v<T1, U1>&& std::is_constructible_v<T2, U2>)>
116 constexpr STDGPU_HOST_DEVICE
117 pair(pair<U1, U2>&& p); // NOLINT(hicpp-explicit-conversions)
118
125 template <class U1,
126 class U2,
127 STDGPU_DETAIL_OVERLOAD_IF(std::is_constructible_v<T1, U1>&& std::is_constructible_v<T2, U2>)>
128 constexpr STDGPU_HOST_DEVICE
129 pair(const pair<U1, U2>&& p); // NOLINT(hicpp-explicit-conversions)
130
135 pair(const pair& p) = default;
136
141 pair(pair&& p) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
142
148 pair&
149 operator=(const pair& p) = default;
150
158 template <class U1,
159 class U2,
160 STDGPU_DETAIL_OVERLOAD_IF(std::is_assignable_v<T1&, const U1&>&& std::is_assignable_v<T2&, const U2&>)>
161 constexpr STDGPU_HOST_DEVICE pair&
163
169 pair&
170 operator=(pair&& p) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
171
179 template <class U1,
180 class U2,
181 STDGPU_DETAIL_OVERLOAD_IF(std::is_assignable_v<T1&, U1>&& std::is_assignable_v<T2&, U2>)>
182 constexpr STDGPU_HOST_DEVICE pair&
184
185 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
187 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
189};
190
198template <class T>
199constexpr STDGPU_HOST_DEVICE T&&
200forward(std::remove_reference_t<T>& t) noexcept;
201
209template <class T>
210constexpr STDGPU_HOST_DEVICE T&&
211forward(std::remove_reference_t<T>&& t) noexcept;
212
220template <class T>
221constexpr STDGPU_HOST_DEVICE std::remove_reference_t<T>&&
222move(T&& t) noexcept;
223
224} // namespace stdgpu
225
226#include <stdgpu/impl/utility_detail.h>
227
228#endif // STDGPU_UTILITY_H
#define STDGPU_HOST_DEVICE
Platform-independent host device function annotation.
Definition: platform.h:77
constexpr STDGPU_HOST_DEVICE std::remove_reference_t< T > && move(T &&t) noexcept
Moves a value.
constexpr STDGPU_HOST_DEVICE T && forward(std::remove_reference_t< T > &t) noexcept
Forwards a value.
constexpr STDGPU_HOST_DEVICE pair(const T1 &x, const T2 &y)
Constructor.
pair & operator=(const pair &p)=default
Default copy assignment operator.
first_type first
Definition: utility.h:186
pair(const pair &p)=default
Default copy constructor.
T2 second_type
Definition: utility.h:46
T1 first_type
Definition: utility.h:45
second_type second
Definition: utility.h:188
constexpr STDGPU_HOST_DEVICE pair(const pair< U1, U2 > &&p)
Move constructor.
constexpr STDGPU_HOST_DEVICE pair & operator=(pair< U1, U2 > &&p)
Move assignment operator.
constexpr STDGPU_HOST_DEVICE pair(pair< U1, U2 > &p)
Copy constructor.
constexpr STDGPU_HOST_DEVICE pair(U1 &&x, U2 &&y)
Constructor.
constexpr STDGPU_HOST_DEVICE pair(pair< U1, U2 > &&p)
Move constructor.
pair(pair &&p)=default
Default move constructor.
pair & operator=(pair &&p)=default
Default move assignment operator.
constexpr STDGPU_HOST_DEVICE pair(const pair< U1, U2 > &p)
Copy constructor.
constexpr STDGPU_HOST_DEVICE pair & operator=(const pair< U1, U2 > &p)
Copy assignment operator.
A pair of two values of potentially different types.
Definition: utility.h:44
~pair()=default
Default Destructor.
constexpr STDGPU_HOST_DEVICE pair()
Constructor.