Skip to content

Commit 2b5efb9

Browse files
committed
Make nvrtc concept macros a but more reliable
1 parent 80246bf commit 2b5efb9

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

libcudacxx/include/cuda/std/__concepts/concept_macros.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ namespace __cccl_unqualified_cuda_std = ::cuda::std; // NOLINT(misc-unused-alias
290290

291291
#else // ^^^ _CCCL_HAS_CONCEPTS() ^^^ / vvv !_CCCL_HAS_CONCEPTS() vvv
292292

293-
# define _CCCL_REQUIRES_EXPR(_TY, ...) _CCCL_REQUIRES_EXPR_IMPL(_TY, _CCCL_COUNTER(), __VA_ARGS__)
293+
# define _CCCL_REQUIRES_EXPR(_TY, ...) _CCCL_REQUIRES_EXPR_IMPL(_TY, _CCCL_REQUIRES_EXPR_ID(_TY), __VA_ARGS__)
294294
# define _CCCL_REQUIRES_EXPR_IMPL(_TY, _ID, ...) \
295295
::__cccl_requires_expr_impl< \
296296
struct _CCCL_PP_CAT(__cccl_requires_expr_detail_, _ID) _CCCL_REQUIRES_EXPR_TPARAM_REFS \
@@ -320,6 +320,32 @@ namespace __cccl_unqualified_cuda_std = ::cuda::std; // NOLINT(misc-unused-alias
320320
# define _CCCL_REQUIRES_EXPR_TPARAM_REF_CASE_DEFAULT(_TY) _TY
321321
# define _CCCL_REQUIRES_EXPR_TPARAM_REF_CASE_VARIADIC(_TY) _CCCL_PP_CAT(_CCCL_REQUIRES_EXPR_EAT_VARIADIC_, _TY)...
322322

323+
// NVRTC does not support __COUNTER__ so we need a better way of defining unique identifiers
324+
# if _CCCL_COMPILER(NVRTC)
325+
326+
// Expands ((Ty...), Ty...) into _CCCL_REQUIRES_EXPR_ID_NO_PAREN(Ty...)
327+
# define _CCCL_REQUIRES_EXPR_ID(_TY, ...) _CCCL_REQUIRES_EXPR_ID_NO_PAREN _TY
328+
329+
// Expands "T1, T2, variadic T3" to "T1_T2_T3_##__LINE__"
330+
# define _CCCL_REQUIRES_EXPR_ID_NO_PAREN(...) \
331+
_CCCL_REQUIRES_EXPR_ID_CONCAT_ALL(_CCCL_PP_FOR_EACH(_CCCL_REQUIRES_EXPR_ID_IMPL, __VA_ARGS__), _CCCL_COUNTER())
332+
333+
// Expands "T1, T2, T3" to "T1T2T3"
334+
# define _CCCL_REQUIRES_EXPR_ID_CONCAT_ALL_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, ...) \
335+
_0##_1##_2##_3##_4##_5##_6##_7##_8##_9
336+
# define _CCCL_REQUIRES_EXPR_ID_CONCAT_ALL(...) \
337+
_CCCL_PP_EVAL(_CCCL_REQUIRES_EXPR_ID_CONCAT_ALL_IMPL, __VA_ARGS__, , , , , , , , , )
338+
339+
// Expands "TY" to "TY" and "variadic TY" to "TY"
340+
# define _CCCL_REQUIRES_EXPR_ID_IMPL(_TY) , _CCCL_PP_SWITCH2(_CCCL_REQUIRES_EXPR_ID_IMPL, _TY)
341+
# define _CCCL_REQUIRES_EXPR_ID_IMPL_SWITCH_variadic _CCCL_PP_CASE(VARIADIC)
342+
# define _CCCL_REQUIRES_EXPR_ID_IMPL_CASE_DEFAULT(_TY) _TY
343+
# define _CCCL_REQUIRES_EXPR_ID_IMPL_CASE_VARIADIC(_TY) _CCCL_PP_CAT(_CCCL_REQUIRES_EXPR_EAT_VARIADIC_, _TY)
344+
345+
# else // ^^^ _CCCL_COMPILER(NVRTC) ^^^^/ vvv !_CCCL_COMPILER(NVRTC)
346+
# define _CCCL_REQUIRES_EXPR_ID(...) _CCCL_COUNTER()
347+
# endif // !_CCCL_COMPILER(NVRTC)
348+
323349
# define _CCCL_REQUIRES_EXPR_EAT_VARIADIC_variadic
324350

325351
# define _CCCL_REQUIRES_EXPR_REQUIREMENTS_(...) \

0 commit comments

Comments
 (0)