1 /* 2 * Copyright (c) 2022 NVIDIA Corporation 3 * 4 * Licensed under the Apache License Version 2.0 with LLVM Exceptions 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * https://llvm.org/LICENSE.txt 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #if __cplusplus < 202002L 19 #error This library requires the use of C++20. 20 #endif 21 22 #include <cassert> 23 24 #define STDEXEC_CAT_(X, ...) X##__VA_ARGS__ 25 #define STDEXEC_CAT(X, ...) STDEXEC_CAT_(X, __VA_ARGS__) 26 27 #define STDEXEC_EXPAND(...) __VA_ARGS__ 28 #define STDEXEC_EVAL(M, ...) M(__VA_ARGS__) 29 30 #define STDEXEC_NOT(X) STDEXEC_CAT(STDEXEC_NOT_, X) 31 #define STDEXEC_NOT_0 1 32 #define STDEXEC_NOT_1 0 33 34 #define STDEXEC_IIF_0(Y, ...) __VA_ARGS__ 35 #define STDEXEC_IIF_1(Y, ...) Y 36 #define STDEXEC_IIF(X, Y, ...) \ 37 STDEXEC_EVAL(STDEXEC_CAT(STDEXEC_IIF_, X), Y, __VA_ARGS__) 38 39 #define STDEXEC_COUNT(...) \ 40 STDEXEC_EXPAND(STDEXEC_COUNT_(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)) 41 #define STDEXEC_COUNT_(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _N, ...) _N 42 43 #define STDEXEC_CHECK(...) STDEXEC_EXPAND(STDEXEC_CHECK_N(__VA_ARGS__, 0, )) 44 #define STDEXEC_CHECK_N(x, n, ...) n 45 #define STDEXEC_PROBE(x) x, 1, 46 47 #if defined(__NVCOMPILER) 48 #define STDEXEC_NVHPC() 1 49 #elif defined(__clang__) 50 #define STDEXEC_CLANG() 1 51 #elif defined(__GNUC__) 52 #define STDEXEC_GCC() 1 53 #elif defined(_MSC_VER) 54 #define STDEXEC_MSVC() 1 55 #endif 56 57 #ifndef STDEXEC_NVHPC 58 #define STDEXEC_NVHPC() 0 59 #endif 60 #ifndef STDEXEC_CLANG 61 #define STDEXEC_CLANG() 0 62 #endif 63 #ifndef STDEXEC_GCC 64 #define STDEXEC_GCC() 0 65 #endif 66 #ifndef STDEXEC_MSVC 67 #define STDEXEC_MSVC() 0 68 #endif 69 70 #if STDEXEC_CLANG() && defined(__CUDACC__) 71 #define STDEXEC_DETAIL_CUDACC_HOST_DEVICE __host__ __device__ 72 #else 73 #define STDEXEC_DETAIL_CUDACC_HOST_DEVICE 74 #endif 75 76 #ifdef STDEXEC_ASSERT 77 #error \ 78 "Redefinition of STDEXEC_ASSERT is not permitted. Define STDEXEC_ASSERT_FN instead." 79 #endif 80 81 #define STDEXEC_ASSERT(_X) \ 82 do \ 83 { \ 84 static_assert(noexcept(_X)); \ 85 STDEXEC_ASSERT_FN(_X); \ 86 } while (false) 87 88 #ifndef STDEXEC_ASSERT_FN 89 #define STDEXEC_ASSERT_FN assert 90 #endif 91