stdgpu/functional.h Source File

stdgpu/functional.h Source File#

stdgpu: stdgpu/functional.h Source File
stdgpu Latest
Efficient STL-like Data Structures on the GPU
functional.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_FUNCTIONAL_H
17#define STDGPU_FUNCTIONAL_H
18
28#include <type_traits>
29
30#include <stdgpu/cstddef.h>
31#include <stdgpu/platform.h>
32#include <stdgpu/utility.h>
33
34namespace stdgpu
35{
36
37namespace detail
38{
39
40template <typename T, bool>
41struct hash_base;
42
43} // namespace detail
44
51template <typename T>
52struct hash : detail::hash_base<T, std::is_enum_v<T>>
53{
54};
55
60template <>
61struct hash<bool>
62{
68 STDGPU_HOST_DEVICE std::size_t
69 operator()(const bool& key) const;
70};
71
76template <>
77struct hash<char>
78{
84 STDGPU_HOST_DEVICE std::size_t
85 operator()(const char& key) const;
86};
87
92template <>
93struct hash<signed char>
94{
100 STDGPU_HOST_DEVICE std::size_t
101 operator()(const signed char& key) const;
102};
103
108template <>
109struct hash<unsigned char>
110{
116 STDGPU_HOST_DEVICE std::size_t
117 operator()(const unsigned char& key) const;
118};
119
124template <>
125struct hash<wchar_t>
126{
132 STDGPU_HOST_DEVICE std::size_t
133 operator()(const wchar_t& key) const;
134};
135
140template <>
141struct hash<char16_t>
142{
148 STDGPU_HOST_DEVICE std::size_t
149 operator()(const char16_t& key) const;
150};
151
156template <>
157struct hash<char32_t>
158{
164 STDGPU_HOST_DEVICE std::size_t
165 operator()(const char32_t& key) const;
166};
167
172template <>
173struct hash<short>
174{
180 STDGPU_HOST_DEVICE std::size_t
181 operator()(const short& key) const;
182};
183
188template <>
189struct hash<unsigned short>
190{
196 STDGPU_HOST_DEVICE std::size_t
197 operator()(const unsigned short& key) const;
198};
199
204template <>
205struct hash<int>
206{
212 STDGPU_HOST_DEVICE std::size_t
213 operator()(const int& key) const;
214};
215
220template <>
221struct hash<unsigned int>
222{
228 STDGPU_HOST_DEVICE std::size_t
229 operator()(const unsigned int& key) const;
230};
231
236template <>
237struct hash<long>
238{
244 STDGPU_HOST_DEVICE std::size_t
245 operator()(const long& key) const;
246};
247
252template <>
253struct hash<unsigned long>
254{
260 STDGPU_HOST_DEVICE std::size_t
261 operator()(const unsigned long& key) const;
262};
263
268template <>
269struct hash<long long>
270{
276 STDGPU_HOST_DEVICE std::size_t
277 operator()(const long long& key) const;
278};
279
284template <>
285struct hash<unsigned long long>
286{
292 STDGPU_HOST_DEVICE std::size_t
293 operator()(const unsigned long long& key) const;
294};
295
300template <>
301struct hash<float>
302{
308 STDGPU_HOST_DEVICE std::size_t
309 operator()(const float& key) const;
310};
311
316template <>
317struct hash<double>
318{
324 STDGPU_HOST_DEVICE std::size_t
325 operator()(const double& key) const;
326};
327
332template <>
333struct hash<long double>
334{
340 STDGPU_HOST_DEVICE std::size_t
341 operator()(const long double& key) const;
342};
343
349{
356 template <typename T>
358 operator()(T&& t) const noexcept;
359};
360
366template <typename T = void>
367struct plus
368{
376 operator()(const T& lhs, const T& rhs) const;
377};
378
383template <>
384struct plus<void>
385{
386 using is_transparent = void;
396 template <typename T, typename U>
398 operator()(T&& lhs, U&& rhs) const -> decltype(forward<T>(lhs) + forward<U>(rhs));
399};
400
406template <typename T = void>
408{
416 operator()(const T& lhs, const T& rhs) const;
417};
418
423template <>
424struct logical_and<void>
425{
426 using is_transparent = void;
436 template <typename T, typename U>
438 operator()(T&& lhs, U&& rhs) const -> decltype(forward<T>(lhs) && forward<U>(rhs));
439};
440
446template <typename T = void>
448{
456 operator()(const T& lhs, const T& rhs) const;
457};
458
463template <>
464struct equal_to<void>
465{
466 using is_transparent = void;
476 template <typename T, typename U>
478 operator()(T&& lhs, U&& rhs) const -> decltype(forward<T>(lhs) == forward<U>(rhs));
479};
480
486template <typename T = void>
488{
495 operator()(const T value) const;
496};
497
502template <>
503struct bit_not<void>
504{
505 using is_transparent = void;
513 template <typename T>
515 operator()(T&& value) const -> decltype(~forward<T>(value));
516};
517
518} // namespace stdgpu
519
520#include <stdgpu/impl/functional_detail.h>
521
522#endif // STDGPU_FUNCTIONAL_H
#define STDGPU_HOST_DEVICE
Platform-independent host device function annotation.
Definition: platform.h:77
void is_transparent
Definition: functional.h:505
STDGPU_HOST_DEVICE auto operator()(T &&value) const -> decltype(~forward< T >(value))
Computes the bitwise NOT on the given value.
STDGPU_HOST_DEVICE T operator()(const T value) const
Computes the bitwise NOT on the given value.
A function to compute bitwise NOT of values.
Definition: functional.h:488
STDGPU_HOST_DEVICE auto operator()(T &&lhs, U &&rhs) const -> decltype(forward< T >(lhs)==forward< U >(rhs))
Compares two values with each other.
void is_transparent
Definition: functional.h:466
STDGPU_HOST_DEVICE bool operator()(const T &lhs, const T &rhs) const
Compares two values with each other.
A function to check equality between two values.
Definition: functional.h:448
STDGPU_HOST_DEVICE std::size_t operator()(const bool &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const char16_t &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const char32_t &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const char &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const double &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const float &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const int &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const long &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const long double &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const long long &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const short &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const signed char &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const unsigned char &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const unsigned int &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const unsigned long &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const unsigned long long &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const unsigned short &key) const
Computes a hash value for the given key.
STDGPU_HOST_DEVICE std::size_t operator()(const wchar_t &key) const
Computes a hash value for the given key.
A function object to compute hash values of provided keys.
Definition: functional.h:53
STDGPU_HOST_DEVICE T && operator()(T &&t) const noexcept
Returns the given value.
A function to return the given value.
Definition: functional.h:349
STDGPU_HOST_DEVICE auto operator()(T &&lhs, U &&rhs) const -> decltype(forward< T >(lhs) &&forward< U >(rhs))
Performs logical AND on the two values.
void is_transparent
Definition: functional.h:426
STDGPU_HOST_DEVICE bool operator()(const T &lhs, const T &rhs) const
Performs logical AND on the two values.
A function to perform logical AND on two values.
Definition: functional.h:408
void is_transparent
Definition: functional.h:386
STDGPU_HOST_DEVICE auto operator()(T &&lhs, U &&rhs) const -> decltype(forward< T >(lhs)+forward< U >(rhs))
Adds the two values.
STDGPU_HOST_DEVICE T operator()(const T &lhs, const T &rhs) const
Adds the two values.
A function to add two values.
Definition: functional.h:368