| 1 |
//@HEADER |
| 2 |
// ************************************************************************ |
| 3 |
// |
| 4 |
// Kokkos v. 4.0 |
| 5 |
// Copyright (2022) National Technology & Engineering |
| 6 |
// Solutions of Sandia, LLC (NTESS). |
| 7 |
// |
| 8 |
// Under the terms of Contract DE-NA0003525 with NTESS, |
| 9 |
// the U.S. Government retains certain rights in this software. |
| 10 |
// |
| 11 |
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
// See https://kokkos.org/LICENSE for license information. |
| 13 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 |
// |
| 15 |
//@HEADER |
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#include "config.hpp" |
| 20 |
|
| 21 |
#include <cstdio> |
| 22 |
#include <cstdlib> |
| 23 |
#include <type_traits> // std::is_void |
| 24 |
#if defined(_MDSPAN_HAS_CUDA) || defined(_MDSPAN_HAS_HIP) || defined(_MDSPAN_HAS_SYCL) |
| 25 |
#include "assert.h" |
| 26 |
#endif |
| 27 |
|
| 28 |
#ifndef _MDSPAN_HOST_DEVICE |
| 29 |
# if defined(_MDSPAN_HAS_CUDA) || defined(_MDSPAN_HAS_HIP) |
| 30 |
# define _MDSPAN_HOST_DEVICE __host__ __device__ |
| 31 |
# else |
| 32 |
# define _MDSPAN_HOST_DEVICE |
| 33 |
# endif |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifndef MDSPAN_FORCE_INLINE_FUNCTION |
| 37 |
# ifdef _MDSPAN_COMPILER_MSVC // Microsoft compilers |
| 38 |
# define MDSPAN_FORCE_INLINE_FUNCTION __forceinline _MDSPAN_HOST_DEVICE |
| 39 |
# else |
| 40 |
# define MDSPAN_FORCE_INLINE_FUNCTION __attribute__((always_inline)) _MDSPAN_HOST_DEVICE |
| 41 |
# endif |
| 42 |
#endif |
| 43 |
|
| 44 |
#ifndef MDSPAN_INLINE_FUNCTION |
| 45 |
# define MDSPAN_INLINE_FUNCTION inline _MDSPAN_HOST_DEVICE |
| 46 |
#endif |
| 47 |
|
| 48 |
#ifndef MDSPAN_FUNCTION |
| 49 |
# define MDSPAN_FUNCTION _MDSPAN_HOST_DEVICE |
| 50 |
#endif |
| 51 |
|
| 52 |
#ifdef _MDSPAN_HAS_HIP |
| 53 |
# define MDSPAN_DEDUCTION_GUIDE _MDSPAN_HOST_DEVICE |
| 54 |
#else |
| 55 |
# define MDSPAN_DEDUCTION_GUIDE |
| 56 |
#endif |
| 57 |
|
| 58 |
// In CUDA defaulted functions do not need host device markup |
| 59 |
#ifndef MDSPAN_INLINE_FUNCTION_DEFAULTED |
| 60 |
# define MDSPAN_INLINE_FUNCTION_DEFAULTED |
| 61 |
#endif |
| 62 |
|
| 63 |
//============================================================================== |
| 64 |
// <editor-fold desc="Preprocessor helpers"> {{{1 |
| 65 |
|
| 66 |
#define MDSPAN_PP_COUNT(...) \ |
| 67 |
_MDSPAN_PP_INTERNAL_EXPAND_ARGS_PRIVATE( \ |
| 68 |
_MDSPAN_PP_INTERNAL_ARGS_AUGMENTER(__VA_ARGS__) \ |
| 69 |
) |
| 70 |
|
| 71 |
#define _MDSPAN_PP_INTERNAL_ARGS_AUGMENTER(...) unused, __VA_ARGS__ |
| 72 |
#define _MDSPAN_PP_INTERNAL_EXPAND(x) x |
| 73 |
#define _MDSPAN_PP_INTERNAL_EXPAND_ARGS_PRIVATE(...) \ |
| 74 |
_MDSPAN_PP_INTERNAL_EXPAND( \ |
| 75 |
_MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ |
| 76 |
__VA_ARGS__, 69, 68, 67, 66, 65, 64, 63, 62, 61, \ |
| 77 |
60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, \ |
| 78 |
48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, \ |
| 79 |
36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, \ |
| 80 |
24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, \ |
| 81 |
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 \ |
| 82 |
) \ |
| 83 |
) |
| 84 |
# define _MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ |
| 85 |
_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, \ |
| 86 |
_10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ |
| 87 |
_20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ |
| 88 |
_30, _31, _32, _33, _34, _35, _36, _37, _38, _39, \ |
| 89 |
_40, _41, _42, _43, _44, _45, _46, _47, _48, _49, \ |
| 90 |
_50, _51, _52, _53, _54, _55, _56, _57, _58, _59, \ |
| 91 |
_60, _61, _62, _63, _64, _65, _66, _67, _68, _69, \ |
| 92 |
_70, count, ...) count \ |
| 93 |
/**/ |
| 94 |
|
| 95 |
#define MDSPAN_PP_STRINGIFY_IMPL(x) #x |
| 96 |
#define MDSPAN_PP_STRINGIFY(x) MDSPAN_PP_STRINGIFY_IMPL(x) |
| 97 |
|
| 98 |
#define MDSPAN_PP_CAT_IMPL(x, y) x ## y |
| 99 |
#define MDSPAN_PP_CAT(x, y) MDSPAN_PP_CAT_IMPL(x, y) |
| 100 |
|
| 101 |
#define MDSPAN_PP_EVAL(X, ...) X(__VA_ARGS__) |
| 102 |
|
| 103 |
#define MDSPAN_PP_REMOVE_PARENS_IMPL(...) __VA_ARGS__ |
| 104 |
#define MDSPAN_PP_REMOVE_PARENS(...) MDSPAN_PP_REMOVE_PARENS_IMPL __VA_ARGS__ |
| 105 |
|
| 106 |
#define MDSPAN_IMPL_STANDARD_NAMESPACE_STRING MDSPAN_PP_STRINGIFY(MDSPAN_IMPL_STANDARD_NAMESPACE) |
| 107 |
#define MDSPAN_IMPL_PROPOSED_NAMESPACE_STRING MDSPAN_PP_STRINGIFY(MDSPAN_IMPL_STANDARD_NAMESPACE) "::" MDSPAN_PP_STRINGIFY(MDSPAN_IMPL_PROPOSED_NAMESPACE) |
| 108 |
|
| 109 |
namespace MDSPAN_IMPL_STANDARD_NAMESPACE { |
| 110 |
namespace detail { |
| 111 |
|
| 112 |
#if defined(_MDSPAN_HAS_CUDA) || defined(_MDSPAN_HAS_HIP) |
| 113 |
MDSPAN_FUNCTION inline void default_precondition_violation_handler(const char* cond, const char* file, unsigned line) |
| 114 |
{ |
| 115 |
printf("%s:%u: precondition failure: `%s`\n", file, line, cond); |
| 116 |
assert(0); |
| 117 |
} |
| 118 |
#elif defined(_MDSPAN_HAS_SYCL) |
| 119 |
MDSPAN_FUNCTION inline void default_precondition_violation_handler(const char* cond, const char* file, unsigned line) |
| 120 |
{ |
| 121 |
sycl::ext::oneapi::experimental::printf("%s:%u: precondition failure: `%s`\n", file, line, cond); |
| 122 |
assert(0); |
| 123 |
} |
| 124 |
#else |
| 125 |
MDSPAN_FUNCTION inline void default_precondition_violation_handler(const char* cond, const char* file, unsigned line) |
| 126 |
{ |
| 127 |
std::fprintf(stderr, "%s:%u: precondition failure: `%s`\n", file, line, cond); |
| 128 |
std::abort(); |
| 129 |
} |
| 130 |
#endif |
| 131 |
|
| 132 |
} // namespace detail |
| 133 |
} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE |
| 134 |
|
| 135 |
#ifndef MDSPAN_IMPL_PRECONDITION_VIOLATION_HANDLER |
| 136 |
#define MDSPAN_IMPL_PRECONDITION_VIOLATION_HANDLER(cond, file, line) \ |
| 137 |
MDSPAN_IMPL_STANDARD_NAMESPACE::detail::default_precondition_violation_handler(cond, file, line) |
| 138 |
#endif |
| 139 |
|
| 140 |
#ifndef MDSPAN_IMPL_CHECK_PRECONDITION |
| 141 |
#ifndef NDEBUG |
| 142 |
#define MDSPAN_IMPL_CHECK_PRECONDITION 0 |
| 143 |
#else |
| 144 |
#define MDSPAN_IMPL_CHECK_PRECONDITION 1 |
| 145 |
#endif |
| 146 |
#endif |
| 147 |
|
| 148 |
namespace MDSPAN_IMPL_STANDARD_NAMESPACE { |
| 149 |
namespace detail { |
| 150 |
|
| 151 |
template <bool check = MDSPAN_IMPL_CHECK_PRECONDITION> |
| 152 |
MDSPAN_FUNCTION constexpr void precondition(const char* cond, const char* file, unsigned line) |
| 153 |
{ |
| 154 |
if (!check) { return; } |
| 155 |
// in case the macro doesn't use the arguments for custom macros |
| 156 |
(void) cond; |
| 157 |
(void) file; |
| 158 |
(void) line; |
| 159 |
MDSPAN_IMPL_PRECONDITION_VIOLATION_HANDLER(cond, file, line); |
| 160 |
} |
| 161 |
|
| 162 |
} // namespace detail |
| 163 |
} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE |
| 164 |
|
| 165 |
#define MDSPAN_IMPL_PRECONDITION(...) \ |
| 166 |
do { \ |
| 167 |
if (!(__VA_ARGS__)) { \ |
| 168 |
MDSPAN_IMPL_STANDARD_NAMESPACE::detail::precondition(#__VA_ARGS__, __FILE__, __LINE__); \ |
| 169 |
} \ |
| 170 |
} while (0) |
| 171 |
|
| 172 |
// </editor-fold> end Preprocessor helpers }}}1 |
| 173 |
//============================================================================== |
| 174 |
|
| 175 |
//============================================================================== |
| 176 |
// <editor-fold desc="Concept emulation"> {{{1 |
| 177 |
|
| 178 |
// These compatibility macros don't help with partial ordering, but they should do the trick |
| 179 |
// for what we need to do with concepts in mdspan |
| 180 |
#ifdef _MDSPAN_USE_CONCEPTS |
| 181 |
# define MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) > requires REQ |
| 182 |
# define MDSPAN_FUNCTION_REQUIRES(PAREN_PREQUALS, FNAME, PAREN_PARAMS, QUALS, REQ) \ |
| 183 |
MDSPAN_PP_REMOVE_PARENS(PAREN_PREQUALS) FNAME PAREN_PARAMS QUALS requires REQ \ |
| 184 |
/**/ |
| 185 |
#else |
| 186 |
# define MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) , typename ::std::enable_if<(REQ), int>::type = 0> |
| 187 |
# define MDSPAN_FUNCTION_REQUIRES(PAREN_PREQUALS, FNAME, PAREN_PARAMS, QUALS, REQ) \ |
| 188 |
MDSPAN_TEMPLATE_REQUIRES( \ |
| 189 |
class __function_requires_ignored=void, \ |
| 190 |
(std::is_void<__function_requires_ignored>::value && REQ) \ |
| 191 |
) MDSPAN_PP_REMOVE_PARENS(PAREN_PREQUALS) FNAME PAREN_PARAMS QUALS \ |
| 192 |
/**/ |
| 193 |
#endif |
| 194 |
|
| 195 |
#if defined(_MDSPAN_COMPILER_MSVC) && (!defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL) |
| 196 |
# define MDSPAN_TEMPLATE_REQUIRES(...) \ |
| 197 |
MDSPAN_PP_CAT( \ |
| 198 |
MDSPAN_PP_CAT(MDSPAN_TEMPLATE_REQUIRES_, MDSPAN_PP_COUNT(__VA_ARGS__))\ |
| 199 |
(__VA_ARGS__), \ |
| 200 |
) \ |
| 201 |
/**/ |
| 202 |
#else |
| 203 |
# define MDSPAN_TEMPLATE_REQUIRES(...) \ |
| 204 |
MDSPAN_PP_EVAL( \ |
| 205 |
MDSPAN_PP_CAT(MDSPAN_TEMPLATE_REQUIRES_, MDSPAN_PP_COUNT(__VA_ARGS__)), \ |
| 206 |
__VA_ARGS__ \ |
| 207 |
) \ |
| 208 |
/**/ |
| 209 |
#endif |
| 210 |
|
| 211 |
#define MDSPAN_TEMPLATE_REQUIRES_2(TP1, REQ) \ |
| 212 |
template<TP1 \ |
| 213 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 214 |
/**/ |
| 215 |
#define MDSPAN_TEMPLATE_REQUIRES_3(TP1, TP2, REQ) \ |
| 216 |
template<TP1, TP2 \ |
| 217 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 218 |
/**/ |
| 219 |
#define MDSPAN_TEMPLATE_REQUIRES_4(TP1, TP2, TP3, REQ) \ |
| 220 |
template<TP1, TP2, TP3 \ |
| 221 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 222 |
/**/ |
| 223 |
#define MDSPAN_TEMPLATE_REQUIRES_5(TP1, TP2, TP3, TP4, REQ) \ |
| 224 |
template<TP1, TP2, TP3, TP4 \ |
| 225 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 226 |
/**/ |
| 227 |
#define MDSPAN_TEMPLATE_REQUIRES_6(TP1, TP2, TP3, TP4, TP5, REQ) \ |
| 228 |
template<TP1, TP2, TP3, TP4, TP5 \ |
| 229 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 230 |
/**/ |
| 231 |
#define MDSPAN_TEMPLATE_REQUIRES_7(TP1, TP2, TP3, TP4, TP5, TP6, REQ) \ |
| 232 |
template<TP1, TP2, TP3, TP4, TP5, TP6 \ |
| 233 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 234 |
/**/ |
| 235 |
#define MDSPAN_TEMPLATE_REQUIRES_8(TP1, TP2, TP3, TP4, TP5, TP6, TP7, REQ) \ |
| 236 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7 \ |
| 237 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 238 |
/**/ |
| 239 |
#define MDSPAN_TEMPLATE_REQUIRES_9(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, REQ) \ |
| 240 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8 \ |
| 241 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 242 |
/**/ |
| 243 |
#define MDSPAN_TEMPLATE_REQUIRES_10(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, REQ) \ |
| 244 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9 \ |
| 245 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 246 |
/**/ |
| 247 |
#define MDSPAN_TEMPLATE_REQUIRES_11(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, REQ) \ |
| 248 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10 \ |
| 249 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 250 |
/**/ |
| 251 |
#define MDSPAN_TEMPLATE_REQUIRES_12(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, REQ) \ |
| 252 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11 \ |
| 253 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 254 |
/**/ |
| 255 |
#define MDSPAN_TEMPLATE_REQUIRES_13(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, REQ) \ |
| 256 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12 \ |
| 257 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 258 |
/**/ |
| 259 |
#define MDSPAN_TEMPLATE_REQUIRES_14(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, REQ) \ |
| 260 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13 \ |
| 261 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 262 |
/**/ |
| 263 |
#define MDSPAN_TEMPLATE_REQUIRES_15(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, REQ) \ |
| 264 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14 \ |
| 265 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 266 |
/**/ |
| 267 |
#define MDSPAN_TEMPLATE_REQUIRES_16(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15, REQ) \ |
| 268 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15 \ |
| 269 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 270 |
/**/ |
| 271 |
#define MDSPAN_TEMPLATE_REQUIRES_17(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15, TP16, REQ) \ |
| 272 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15, TP16 \ |
| 273 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 274 |
/**/ |
| 275 |
#define MDSPAN_TEMPLATE_REQUIRES_18(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, REQ) \ |
| 276 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17 \ |
| 277 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 278 |
/**/ |
| 279 |
#define MDSPAN_TEMPLATE_REQUIRES_19(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, REQ) \ |
| 280 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18 \ |
| 281 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 282 |
/**/ |
| 283 |
#define MDSPAN_TEMPLATE_REQUIRES_20(TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, REQ) \ |
| 284 |
template<TP1, TP2, TP3, TP4, TP5, TP6, TP7, TP8, TP9, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19 \ |
| 285 |
MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ |
| 286 |
/**/ |
| 287 |
|
| 288 |
#define MDSPAN_INSTANTIATE_ONLY_IF_USED \ |
| 289 |
MDSPAN_TEMPLATE_REQUIRES( \ |
| 290 |
class __instantiate_only_if_used_tparam=void, \ |
| 291 |
( _MDSPAN_TRAIT(std::is_void, __instantiate_only_if_used_tparam) ) \ |
| 292 |
) \ |
| 293 |
/**/ |
| 294 |
|
| 295 |
// </editor-fold> end Concept emulation }}}1 |
| 296 |
//============================================================================== |
| 297 |
|
| 298 |
//============================================================================== |
| 299 |
// <editor-fold desc="inline variables"> {{{1 |
| 300 |
|
| 301 |
#ifdef _MDSPAN_USE_INLINE_VARIABLES |
| 302 |
# define _MDSPAN_INLINE_VARIABLE inline |
| 303 |
#else |
| 304 |
# define _MDSPAN_INLINE_VARIABLE |
| 305 |
#endif |
| 306 |
|
| 307 |
// </editor-fold> end inline variables }}}1 |
| 308 |
//============================================================================== |
| 309 |
|
| 310 |
//============================================================================== |
| 311 |
// <editor-fold desc="Return type deduction"> {{{1 |
| 312 |
|
| 313 |
#if _MDSPAN_USE_RETURN_TYPE_DEDUCTION |
| 314 |
# define _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ |
| 315 |
auto MDSPAN_PP_REMOVE_PARENS(SIGNATURE) { return MDSPAN_PP_REMOVE_PARENS(BODY); } |
| 316 |
# define _MDSPAN_DEDUCE_DECLTYPE_AUTO_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ |
| 317 |
decltype(auto) MDSPAN_PP_REMOVE_PARENS(SIGNATURE) { return MDSPAN_PP_REMOVE_PARENS(BODY); } |
| 318 |
#else |
| 319 |
# define _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ |
| 320 |
auto MDSPAN_PP_REMOVE_PARENS(SIGNATURE) \ |
| 321 |
-> std::remove_cv_t<std::remove_reference_t<decltype(BODY)>> \ |
| 322 |
{ return MDSPAN_PP_REMOVE_PARENS(BODY); } |
| 323 |
# define _MDSPAN_DEDUCE_DECLTYPE_AUTO_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ |
| 324 |
auto MDSPAN_PP_REMOVE_PARENS(SIGNATURE) \ |
| 325 |
-> decltype(BODY) \ |
| 326 |
{ return MDSPAN_PP_REMOVE_PARENS(BODY); } |
| 327 |
|
| 328 |
#endif |
| 329 |
|
| 330 |
// </editor-fold> end Return type deduction }}}1 |
| 331 |
//============================================================================== |
| 332 |
|
| 333 |
//============================================================================== |
| 334 |
// <editor-fold desc="fold expressions"> {{{1 |
| 335 |
|
| 336 |
struct __mdspan_enable_fold_comma { }; |
| 337 |
|
| 338 |
#ifdef _MDSPAN_USE_FOLD_EXPRESSIONS |
| 339 |
# define _MDSPAN_FOLD_AND(...) ((__VA_ARGS__) && ...) |
| 340 |
# define _MDSPAN_FOLD_AND_TEMPLATE(...) ((__VA_ARGS__) && ...) |
| 341 |
# define _MDSPAN_FOLD_OR(...) ((__VA_ARGS__) || ...) |
| 342 |
# define _MDSPAN_FOLD_ASSIGN_LEFT(INIT, ...) (INIT = ... = (__VA_ARGS__)) |
| 343 |
# define _MDSPAN_FOLD_ASSIGN_RIGHT(PACK, ...) (PACK = ... = (__VA_ARGS__)) |
| 344 |
# define _MDSPAN_FOLD_TIMES_RIGHT(PACK, ...) (PACK * ... * (__VA_ARGS__)) |
| 345 |
# define _MDSPAN_FOLD_PLUS_RIGHT(PACK, ...) (PACK + ... + (__VA_ARGS__)) |
| 346 |
# define _MDSPAN_FOLD_COMMA(...) ((__VA_ARGS__), ...) |
| 347 |
#else |
| 348 |
|
| 349 |
namespace MDSPAN_IMPL_STANDARD_NAMESPACE { |
| 350 |
|
| 351 |
namespace __fold_compatibility_impl { |
| 352 |
|
| 353 |
// We could probably be more clever here, but at the (small) risk of losing some compiler understanding. For the |
| 354 |
// few operations we need, it's not worth generalizing over the operation |
| 355 |
|
| 356 |
#if _MDSPAN_USE_RETURN_TYPE_DEDUCTION |
| 357 |
|
| 358 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 359 |
constexpr decltype(auto) __fold_right_and_impl() { |
| 360 |
return true; |
| 361 |
} |
| 362 |
|
| 363 |
template <class Arg, class... Args> |
| 364 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 365 |
constexpr decltype(auto) __fold_right_and_impl(Arg&& arg, Args&&... args) { |
| 366 |
return ((Arg&&)arg) && __fold_compatibility_impl::__fold_right_and_impl((Args&&)args...); |
| 367 |
} |
| 368 |
|
| 369 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 370 |
constexpr decltype(auto) __fold_right_or_impl() { |
| 371 |
return false; |
| 372 |
} |
| 373 |
|
| 374 |
template <class Arg, class... Args> |
| 375 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 376 |
constexpr auto __fold_right_or_impl(Arg&& arg, Args&&... args) { |
| 377 |
return ((Arg&&)arg) || __fold_compatibility_impl::__fold_right_or_impl((Args&&)args...); |
| 378 |
} |
| 379 |
|
| 380 |
template <class Arg1> |
| 381 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 382 |
constexpr auto __fold_left_assign_impl(Arg1&& arg1) { |
| 383 |
return (Arg1&&)arg1; |
| 384 |
} |
| 385 |
|
| 386 |
template <class Arg1, class Arg2, class... Args> |
| 387 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 388 |
constexpr auto __fold_left_assign_impl(Arg1&& arg1, Arg2&& arg2, Args&&... args) { |
| 389 |
return __fold_compatibility_impl::__fold_left_assign_impl((((Arg1&&)arg1) = ((Arg2&&)arg2)), (Args&&)args...); |
| 390 |
} |
| 391 |
|
| 392 |
template <class Arg1> |
| 393 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 394 |
constexpr auto __fold_right_assign_impl(Arg1&& arg1) { |
| 395 |
return (Arg1&&)arg1; |
| 396 |
} |
| 397 |
|
| 398 |
template <class Arg1, class Arg2, class... Args> |
| 399 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 400 |
constexpr auto __fold_right_assign_impl(Arg1&& arg1, Arg2&& arg2, Args&&... args) { |
| 401 |
return ((Arg1&&)arg1) = __fold_compatibility_impl::__fold_right_assign_impl((Arg2&&)arg2, (Args&&)args...); |
| 402 |
} |
| 403 |
|
| 404 |
template <class Arg1> |
| 405 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 406 |
constexpr auto __fold_right_plus_impl(Arg1&& arg1) { |
| 407 |
return (Arg1&&)arg1; |
| 408 |
} |
| 409 |
|
| 410 |
template <class Arg1, class Arg2, class... Args> |
| 411 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 412 |
constexpr auto __fold_right_plus_impl(Arg1&& arg1, Arg2&& arg2, Args&&... args) { |
| 413 |
return ((Arg1&&)arg1) + __fold_compatibility_impl::__fold_right_plus_impl((Arg2&&)arg2, (Args&&)args...); |
| 414 |
} |
| 415 |
|
| 416 |
template <class Arg1> |
| 417 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 418 |
constexpr auto __fold_right_times_impl(Arg1&& arg1) { |
| 419 |
return (Arg1&&)arg1; |
| 420 |
} |
| 421 |
|
| 422 |
template <class Arg1, class Arg2, class... Args> |
| 423 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 424 |
constexpr auto __fold_right_times_impl(Arg1&& arg1, Arg2&& arg2, Args&&... args) { |
| 425 |
return ((Arg1&&)arg1) * __fold_compatibility_impl::__fold_right_times_impl((Arg2&&)arg2, (Args&&)args...); |
| 426 |
} |
| 427 |
|
| 428 |
#else |
| 429 |
|
| 430 |
//------------------------------------------------------------------------------ |
| 431 |
// <editor-fold desc="right and"> {{{2 |
| 432 |
|
| 433 |
template <class... Args> |
| 434 |
struct __fold_right_and_impl_; |
| 435 |
template <> |
| 436 |
struct __fold_right_and_impl_<> { |
| 437 |
using __rv = bool; |
| 438 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 439 |
static constexpr __rv |
| 440 |
__impl() noexcept { |
| 441 |
return true; |
| 442 |
} |
| 443 |
}; |
| 444 |
template <class Arg, class... Args> |
| 445 |
struct __fold_right_and_impl_<Arg, Args...> { |
| 446 |
using __next_t = __fold_right_and_impl_<Args...>; |
| 447 |
using __rv = decltype(std::declval<Arg>() && std::declval<typename __next_t::__rv>()); |
| 448 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 449 |
static constexpr __rv |
| 450 |
__impl(Arg&& arg, Args&&... args) noexcept { |
| 451 |
return ((Arg&&)arg) && __next_t::__impl((Args&&)args...); |
| 452 |
} |
| 453 |
}; |
| 454 |
|
| 455 |
template <class... Args> |
| 456 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 457 |
constexpr typename __fold_right_and_impl_<Args...>::__rv |
| 458 |
__fold_right_and_impl(Args&&... args) { |
| 459 |
return __fold_right_and_impl_<Args...>::__impl((Args&&)args...); |
| 460 |
} |
| 461 |
|
| 462 |
// </editor-fold> end right and }}}2 |
| 463 |
//------------------------------------------------------------------------------ |
| 464 |
|
| 465 |
//------------------------------------------------------------------------------ |
| 466 |
// <editor-fold desc="right or"> {{{2 |
| 467 |
|
| 468 |
template <class... Args> |
| 469 |
struct __fold_right_or_impl_; |
| 470 |
template <> |
| 471 |
struct __fold_right_or_impl_<> { |
| 472 |
using __rv = bool; |
| 473 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 474 |
static constexpr __rv |
| 475 |
__impl() noexcept { |
| 476 |
return false; |
| 477 |
} |
| 478 |
}; |
| 479 |
template <class Arg, class... Args> |
| 480 |
struct __fold_right_or_impl_<Arg, Args...> { |
| 481 |
using __next_t = __fold_right_or_impl_<Args...>; |
| 482 |
using __rv = decltype(std::declval<Arg>() || std::declval<typename __next_t::__rv>()); |
| 483 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 484 |
static constexpr __rv |
| 485 |
__impl(Arg&& arg, Args&&... args) noexcept { |
| 486 |
return ((Arg&&)arg) || __next_t::__impl((Args&&)args...); |
| 487 |
} |
| 488 |
}; |
| 489 |
|
| 490 |
template <class... Args> |
| 491 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 492 |
constexpr typename __fold_right_or_impl_<Args...>::__rv |
| 493 |
__fold_right_or_impl(Args&&... args) { |
| 494 |
return __fold_right_or_impl_<Args...>::__impl((Args&&)args...); |
| 495 |
} |
| 496 |
|
| 497 |
// </editor-fold> end right or }}}2 |
| 498 |
//------------------------------------------------------------------------------ |
| 499 |
|
| 500 |
//------------------------------------------------------------------------------ |
| 501 |
// <editor-fold desc="right plus"> {{{2 |
| 502 |
|
| 503 |
template <class... Args> |
| 504 |
struct __fold_right_plus_impl_; |
| 505 |
template <class Arg> |
| 506 |
struct __fold_right_plus_impl_<Arg> { |
| 507 |
using __rv = Arg&&; |
| 508 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 509 |
static constexpr __rv |
| 510 |
__impl(Arg&& arg) noexcept { |
| 511 |
return (Arg&&)arg; |
| 512 |
} |
| 513 |
}; |
| 514 |
template <class Arg1, class Arg2, class... Args> |
| 515 |
struct __fold_right_plus_impl_<Arg1, Arg2, Args...> { |
| 516 |
using __next_t = __fold_right_plus_impl_<Arg2, Args...>; |
| 517 |
using __rv = decltype(std::declval<Arg1>() + std::declval<typename __next_t::__rv>()); |
| 518 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 519 |
static constexpr __rv |
| 520 |
__impl(Arg1&& arg, Arg2&& arg2, Args&&... args) noexcept { |
| 521 |
return ((Arg1&&)arg) + __next_t::__impl((Arg2&&)arg2, (Args&&)args...); |
| 522 |
} |
| 523 |
}; |
| 524 |
|
| 525 |
template <class... Args> |
| 526 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 527 |
constexpr typename __fold_right_plus_impl_<Args...>::__rv |
| 528 |
__fold_right_plus_impl(Args&&... args) { |
| 529 |
return __fold_right_plus_impl_<Args...>::__impl((Args&&)args...); |
| 530 |
} |
| 531 |
|
| 532 |
// </editor-fold> end right plus }}}2 |
| 533 |
//------------------------------------------------------------------------------ |
| 534 |
|
| 535 |
//------------------------------------------------------------------------------ |
| 536 |
// <editor-fold desc="right times"> {{{2 |
| 537 |
|
| 538 |
template <class... Args> |
| 539 |
struct __fold_right_times_impl_; |
| 540 |
template <class Arg> |
| 541 |
struct __fold_right_times_impl_<Arg> { |
| 542 |
using __rv = Arg&&; |
| 543 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 544 |
static constexpr __rv |
| 545 |
__impl(Arg&& arg) noexcept { |
| 546 |
return (Arg&&)arg; |
| 547 |
} |
| 548 |
}; |
| 549 |
template <class Arg1, class Arg2, class... Args> |
| 550 |
struct __fold_right_times_impl_<Arg1, Arg2, Args...> { |
| 551 |
using __next_t = __fold_right_times_impl_<Arg2, Args...>; |
| 552 |
using __rv = decltype(std::declval<Arg1>() * std::declval<typename __next_t::__rv>()); |
| 553 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 554 |
static constexpr __rv |
| 555 |
__impl(Arg1&& arg, Arg2&& arg2, Args&&... args) noexcept { |
| 556 |
return ((Arg1&&)arg) * __next_t::__impl((Arg2&&)arg2, (Args&&)args...); |
| 557 |
} |
| 558 |
}; |
| 559 |
|
| 560 |
template <class... Args> |
| 561 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 562 |
constexpr typename __fold_right_times_impl_<Args...>::__rv |
| 563 |
__fold_right_times_impl(Args&&... args) { |
| 564 |
return __fold_right_times_impl_<Args...>::__impl((Args&&)args...); |
| 565 |
} |
| 566 |
|
| 567 |
// </editor-fold> end right times }}}2 |
| 568 |
//------------------------------------------------------------------------------ |
| 569 |
|
| 570 |
//------------------------------------------------------------------------------ |
| 571 |
// <editor-fold desc="right assign"> {{{2 |
| 572 |
|
| 573 |
template <class... Args> |
| 574 |
struct __fold_right_assign_impl_; |
| 575 |
template <class Arg> |
| 576 |
struct __fold_right_assign_impl_<Arg> { |
| 577 |
using __rv = Arg&&; |
| 578 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 579 |
static constexpr __rv |
| 580 |
__impl(Arg&& arg) noexcept { |
| 581 |
return (Arg&&)arg; |
| 582 |
} |
| 583 |
}; |
| 584 |
template <class Arg1, class Arg2, class... Args> |
| 585 |
struct __fold_right_assign_impl_<Arg1, Arg2, Args...> { |
| 586 |
using __next_t = __fold_right_assign_impl_<Arg2, Args...>; |
| 587 |
using __rv = decltype(std::declval<Arg1>() = std::declval<typename __next_t::__rv>()); |
| 588 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 589 |
static constexpr __rv |
| 590 |
__impl(Arg1&& arg, Arg2&& arg2, Args&&... args) noexcept { |
| 591 |
return ((Arg1&&)arg) = __next_t::__impl((Arg2&&)arg2, (Args&&)args...); |
| 592 |
} |
| 593 |
}; |
| 594 |
|
| 595 |
template <class... Args> |
| 596 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 597 |
constexpr typename __fold_right_assign_impl_<Args...>::__rv |
| 598 |
__fold_right_assign_impl(Args&&... args) { |
| 599 |
return __fold_right_assign_impl_<Args...>::__impl((Args&&)args...); |
| 600 |
} |
| 601 |
|
| 602 |
// </editor-fold> end right assign }}}2 |
| 603 |
//------------------------------------------------------------------------------ |
| 604 |
|
| 605 |
//------------------------------------------------------------------------------ |
| 606 |
// <editor-fold desc="left assign"> {{{2 |
| 607 |
|
| 608 |
template <class... Args> |
| 609 |
struct __fold_left_assign_impl_; |
| 610 |
template <class Arg> |
| 611 |
struct __fold_left_assign_impl_<Arg> { |
| 612 |
using __rv = Arg&&; |
| 613 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 614 |
static constexpr __rv |
| 615 |
__impl(Arg&& arg) noexcept { |
| 616 |
return (Arg&&)arg; |
| 617 |
} |
| 618 |
}; |
| 619 |
template <class Arg1, class Arg2, class... Args> |
| 620 |
struct __fold_left_assign_impl_<Arg1, Arg2, Args...> { |
| 621 |
using __assign_result_t = decltype(std::declval<Arg1>() = std::declval<Arg2>()); |
| 622 |
using __next_t = __fold_left_assign_impl_<__assign_result_t, Args...>; |
| 623 |
using __rv = typename __next_t::__rv; |
| 624 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 625 |
static constexpr __rv |
| 626 |
__impl(Arg1&& arg, Arg2&& arg2, Args&&... args) noexcept { |
| 627 |
return __next_t::__impl(((Arg1&&)arg) = (Arg2&&)arg2, (Args&&)args...); |
| 628 |
} |
| 629 |
}; |
| 630 |
|
| 631 |
template <class... Args> |
| 632 |
MDSPAN_FORCE_INLINE_FUNCTION |
| 633 |
constexpr typename __fold_left_assign_impl_<Args...>::__rv |
| 634 |
__fold_left_assign_impl(Args&&... args) { |
| 635 |
return __fold_left_assign_impl_<Args...>::__impl((Args&&)args...); |
| 636 |
} |
| 637 |
|
| 638 |
// </editor-fold> end left assign }}}2 |
| 639 |
//------------------------------------------------------------------------------ |
| 640 |
|
| 641 |
#endif |
| 642 |
|
| 643 |
|
| 644 |
template <class... Args> |
| 645 |
constexpr __mdspan_enable_fold_comma __fold_comma_impl(Args&&...) noexcept { return { }; } |
| 646 |
|
| 647 |
template <bool... Bs> |
| 648 |
struct __bools; |
| 649 |
|
| 650 |
} // __fold_compatibility_impl |
| 651 |
|
| 652 |
} // end namespace MDSPAN_IMPL_STANDARD_NAMESPACE |
| 653 |
|
| 654 |
# define _MDSPAN_FOLD_AND(...) MDSPAN_IMPL_STANDARD_NAMESPACE::__fold_compatibility_impl::__fold_right_and_impl((__VA_ARGS__)...) |
| 655 |
# define _MDSPAN_FOLD_OR(...) MDSPAN_IMPL_STANDARD_NAMESPACE::__fold_compatibility_impl::__fold_right_or_impl((__VA_ARGS__)...) |
| 656 |
# define _MDSPAN_FOLD_ASSIGN_LEFT(INIT, ...) MDSPAN_IMPL_STANDARD_NAMESPACE::__fold_compatibility_impl::__fold_left_assign_impl(INIT, (__VA_ARGS__)...) |
| 657 |
# define _MDSPAN_FOLD_ASSIGN_RIGHT(PACK, ...) MDSPAN_IMPL_STANDARD_NAMESPACE::__fold_compatibility_impl::__fold_right_assign_impl((PACK)..., __VA_ARGS__) |
| 658 |
# define _MDSPAN_FOLD_TIMES_RIGHT(PACK, ...) MDSPAN_IMPL_STANDARD_NAMESPACE::__fold_compatibility_impl::__fold_right_times_impl((PACK)..., __VA_ARGS__) |
| 659 |
# define _MDSPAN_FOLD_PLUS_RIGHT(PACK, ...) MDSPAN_IMPL_STANDARD_NAMESPACE::__fold_compatibility_impl::__fold_right_plus_impl((PACK)..., __VA_ARGS__) |
| 660 |
# define _MDSPAN_FOLD_COMMA(...) MDSPAN_IMPL_STANDARD_NAMESPACE::__fold_compatibility_impl::__fold_comma_impl((__VA_ARGS__)...) |
| 661 |
|
| 662 |
# define _MDSPAN_FOLD_AND_TEMPLATE(...) \ |
| 663 |
_MDSPAN_TRAIT(std::is_same, __fold_compatibility_impl::__bools<(__VA_ARGS__)..., true>, __fold_compatibility_impl::__bools<true, (__VA_ARGS__)...>) |
| 664 |
|
| 665 |
#endif |
| 666 |
|
| 667 |
// </editor-fold> end fold expressions }}}1 |
| 668 |
//============================================================================== |
| 669 |
|
| 670 |
//============================================================================== |
| 671 |
// <editor-fold desc="Variable template compatibility"> {{{1 |
| 672 |
|
| 673 |
#if _MDSPAN_USE_VARIABLE_TEMPLATES |
| 674 |
# define _MDSPAN_TRAIT(TRAIT, ...) TRAIT##_v<__VA_ARGS__> |
| 675 |
#else |
| 676 |
# define _MDSPAN_TRAIT(TRAIT, ...) TRAIT<__VA_ARGS__>::value |
| 677 |
#endif |
| 678 |
|
| 679 |
// </editor-fold> end Variable template compatibility }}}1 |
| 680 |
//============================================================================== |
| 681 |
|
| 682 |
//============================================================================== |
| 683 |
// <editor-fold desc="Pre-C++14 constexpr"> {{{1 |
| 684 |
|
| 685 |
#if _MDSPAN_USE_CONSTEXPR_14 |
| 686 |
# define _MDSPAN_CONSTEXPR_14 constexpr |
| 687 |
// Workaround for a bug (I think?) in EDG frontends |
| 688 |
# ifdef __EDG__ |
| 689 |
# define _MDSPAN_CONSTEXPR_14_DEFAULTED |
| 690 |
# else |
| 691 |
# define _MDSPAN_CONSTEXPR_14_DEFAULTED constexpr |
| 692 |
# endif |
| 693 |
#else |
| 694 |
# define _MDSPAN_CONSTEXPR_14 |
| 695 |
# define _MDSPAN_CONSTEXPR_14_DEFAULTED |
| 696 |
#endif |
| 697 |
|
| 698 |
// </editor-fold> end Pre-C++14 constexpr }}}1 |
| 699 |
//============================================================================== |