Project
Loading...
Searching...
No Matches
GPUGetConstexpr.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef GPUGETCONSTEXPR_H
16#define GPUGETCONSTEXPR_H
17
18#include "GPUCommonDef.h"
19#ifndef GPUCA_GPUCODE_DEVICE
20#include <type_traits>
21#endif
22
23// This is a temporary workaround required for clang (with c++20), until we can go to C++23 with P2280R4, which allows getting constexpr static values from references
24
25#if defined(__clang__) && __cplusplus >= 202002L && __cplusplus < 202302L
26
27namespace o2::gpu::internal
28{
29
30#define GPUCA_GET_CONSTEXPR(obj, val) ( \
31 std::is_member_pointer_v<decltype(&std::remove_reference_t<decltype(obj)>::val)> ? o2::gpu::internal::getConstexpr(&std::remove_reference_t<decltype(obj)>::val, o2::gpu::internal::getConstexprHelper<decltype(&std::remove_reference_t<decltype(obj)>::val), decltype(&obj)>(&obj).value) : o2::gpu::internal::getConstexpr(&std::remove_reference_t<decltype(obj)>::val, o2::gpu::internal::getConstexprHelper<decltype(&std::remove_reference_t<decltype(obj)>::val), decltype(&obj)>().value))
32
33template <class T, class S>
34struct getConstexprHelper;
35
36template <class T, class S>
37 requires(!std::is_member_pointer_v<T>)
38struct getConstexprHelper<T, S> {
39 GPUdi() constexpr getConstexprHelper(const void* = nullptr) {}
40 static constexpr const void* value = nullptr;
41};
42
43template <class T, class S>
44 requires(std::is_member_pointer_v<T>)
45struct getConstexprHelper<T, S> {
46 GPUdi() constexpr getConstexprHelper(const S& v) : value(v) {}
47 GPUdDefault() constexpr getConstexprHelper() = default;
48 const S value = nullptr;
49};
50
51GPUdi() constexpr auto getConstexpr(const auto* v, const void* = nullptr)
52{
53 return *v;
54}
55
56GPUdi() constexpr auto getConstexpr(const auto v, const auto w)
57{
58 return w->*v;
59}
60
61} // namespace o2::gpu::internal
62
63#else // __clang__
64
65#define GPUCA_GET_CONSTEXPR(obj, val) (obj).val
66
67#endif
68
69#endif // GPUGETCONSTEXPR_H
#define GPUdDefault()
const GLdouble * v
Definition glcorearb.h:832
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
GPUdi() o2
Definition TrackTRD.h:38