Skip to content

Commit f95246d

Browse files
ericnieblerdavebayer
authored andcommitted
minor consistency improvements in concepts macros (NVIDIA#2928)
1 parent 4d8553a commit f95246d

File tree

1 file changed

+52
-55
lines changed

1 file changed

+52
-55
lines changed

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

+52-55
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
# pragma system_header
2525
#endif // no system header
2626

27+
#include <cuda/std/cstddef> // for size_t
28+
2729
////////////////////////////////////////////////////////////////////////////////
2830
// _CCCL_TEMPLATE
2931
// Usage:
@@ -50,51 +52,46 @@ using __cccl_enable_if_t = typename __cccl_select<_Bp>::template type<_Tp>;
5052
template <class _Tp, bool _Bp>
5153
using __cccl_requires_t = typename __cccl_select<_Bp>::template type<_Tp>;
5254

53-
#if (defined(__cpp_concepts) && _CCCL_STD_VER >= 2020)
55+
#if (defined(__cpp_concepts) && _CCCL_STD_VER >= 2020) || defined(_CCCL_DOXYGEN_INVOKED)
5456
# define _CCCL_TEMPLATE(...) template <__VA_ARGS__>
5557
# define _CCCL_REQUIRES(...) requires __VA_ARGS__
5658
# define _CCCL_AND &&
5759
# define _CCCL_TRAILING_REQUIRES_AUX_(...) requires __VA_ARGS__
5860
# define _CCCL_TRAILING_REQUIRES(...) ->__VA_ARGS__ _CCCL_TRAILING_REQUIRES_AUX_
5961
#else // ^^^ __cpp_concepts ^^^ / vvv !__cpp_concepts vvv
6062
# define _CCCL_TEMPLATE(...) template <__VA_ARGS__
61-
# define _CCCL_REQUIRES(...) , bool _CCCL_true_ = true, __cccl_enable_if_t < __VA_ARGS__ && _CCCL_true_, int > = 0 >
62-
# define _CCCL_AND &&_CCCL_true_, int > = 0, __cccl_enable_if_t <
63+
# define _CCCL_REQUIRES(...) , bool __cccl_true_ = true, __cccl_enable_if_t < __VA_ARGS__ && __cccl_true_, int > = 0 >
64+
# define _CCCL_AND &&__cccl_true_, int > = 0, __cccl_enable_if_t <
6365
# define _CCCL_TRAILING_REQUIRES_AUX_(...) , __VA_ARGS__ >
6466
# define _CCCL_TRAILING_REQUIRES(...) ->__cccl_requires_t < __VA_ARGS__ _CCCL_TRAILING_REQUIRES_AUX_
6567
#endif // !__cpp_concepts
6668

6769
#if _CCCL_STD_VER >= 2014
6870

69-
namespace __cccl_concept
70-
{
71-
72-
template <typename...>
73-
struct _Tag;
71+
template <class...>
72+
struct __cccl_tag;
7473

7574
template <class>
76-
_LIBCUDACXX_HIDE_FROM_ABI constexpr bool __is_true()
75+
_LIBCUDACXX_HIDE_FROM_ABI constexpr bool __cccl_is_true()
7776
{
7877
return true;
7978
}
8079

81-
# if _CCCL_COMPILER(CLANG) || _CCCL_COMPILER(MSVC)
80+
# if _CCCL_COMPILER(MSVC)
8281
template <bool _Bp>
8382
_LIBCUDACXX_HIDE_FROM_ABI __cccl_enable_if_t<_Bp> __cccl_requires()
8483
{}
85-
# else // ^^^ _CCCL_COMPILER(CLANG) || _CCCL_COMPILER(MSVC) ^^^ / vvv other compilers vvv
84+
# else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC) vvv
8685
template <bool _Bp, __cccl_enable_if_t<_Bp, int> = 0>
8786
_CCCL_INLINE_VAR constexpr int __cccl_requires = 0;
88-
# endif // !_CCCL_COMPILER(CLANG) && !_CCCL_COMPILER(MSVC)
87+
# endif // !_CCCL_COMPILER(MSVC)
8988

9089
template <class _Tp, class... _Args>
91-
_LIBCUDACXX_HIDE_FROM_ABI auto __cccl_make_dependent(_Tp*, _Tag<_Args...>*) -> _Tp;
90+
_LIBCUDACXX_HIDE_FROM_ABI auto __cccl_make_dependent(_Tp*, __cccl_tag<_Args...>*) -> _Tp;
9291

9392
template <class _Impl, class... _Args>
94-
using __requires_expr_impl =
95-
decltype(__cccl_make_dependent(static_cast<_Impl*>(nullptr), static_cast<_Tag<void, _Args...>*>(nullptr)));
96-
97-
} // namespace __cccl_concept
93+
using __cccl_requires_expr_impl =
94+
decltype(__cccl_make_dependent(static_cast<_Impl*>(nullptr), static_cast<__cccl_tag<void, _Args...>*>(nullptr)));
9895

9996
// So that we can refer to the ::cuda::std namespace below
10097
_LIBCUDACXX_BEGIN_NAMESPACE_STD
@@ -107,21 +104,21 @@ _LIBCUDACXX_END_NAMESPACE_STD
107104
//
108105
// where ::concept is a fully qualified name, would not compile. The
109106
// _CUDA_VSTD macro is fully qualified.
110-
namespace __unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-decls)
107+
namespace __cccl_unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-decls)
111108

112109
# if _CCCL_CUDACC_BELOW(12, 2)
113-
# define _CCCL_CONCEPT_VSTD __unqualified_cuda_std // must not be fully qualified
110+
# define _CCCL_CONCEPT_VSTD __cccl_unqualified_cuda_std // must not be fully qualified
114111
# else
115112
# define _CCCL_CONCEPT_VSTD _CUDA_VSTD
116113
# endif
117114

118115
# define _CCCL_CONCEPT_FRAGMENT_REQS_M0(_REQ) _CCCL_CONCEPT_FRAGMENT_REQS_SELECT_(_REQ)(_REQ)
119116
# define _CCCL_CONCEPT_FRAGMENT_REQS_M1(_REQ) _CCCL_PP_EXPAND _REQ
120117
# define _CCCL_CONCEPT_FRAGMENT_REQS_(...) {_CCCL_PP_FOR_EACH(_CCCL_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__)}
121-
# define _CCCL_CONCEPT_FRAGMENT_REQS_SELECT_(_REQ) \
122-
_CCCL_PP_CAT3(_CCCL_CONCEPT_FRAGMENT_REQS_SELECT_, \
123-
_CCCL_PP_EVAL(_CCCL_PP_CHECK, _CCCL_PP_CAT3(_CCCL_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_, _REQ))) \
124-
/**/
118+
# define _CCCL_CONCEPT_FRAGMENT_REQS_SELECT_(_REQ) \
119+
_CCCL_PP_CAT3(_CCCL_CONCEPT_FRAGMENT_REQS_SELECT_, \
120+
_CCCL_PP_EVAL(_CCCL_PP_CHECK, _CCCL_PP_CAT3(_CCCL_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_, _REQ)))
121+
125122
# define _CCCL_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_requires _CCCL_PP_PROBE_N(~, 1)
126123
# define _CCCL_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_noexcept _CCCL_PP_PROBE_N(~, 2)
127124
# define _CCCL_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_typename _CCCL_PP_PROBE_N(~, 3)
@@ -132,15 +129,14 @@ namespace __unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-decls
132129
# define _CCCL_CONCEPT_FRAGMENT_REQS_SELECT_2 _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT
133130
# define _CCCL_CONCEPT_FRAGMENT_REQS_SELECT_3 _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT
134131
# define _CCCL_CONCEPT_FRAGMENT_REQS_SELECT_4 _CCCL_CONCEPT_FRAGMENT_REQS_SAME_AS
132+
135133
# define _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT(_REQ) \
136134
_CCCL_PP_CAT4(_CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_, _REQ)
137135
# define _CCCL_PP_EAT_TYPENAME_PROBE_typename _CCCL_PP_PROBE(~)
138136
# define _CCCL_PP_EAT_TYPENAME_SELECT_(_Xp, ...) \
139137
_CCCL_PP_CAT3(_CCCL_PP_EAT_TYPENAME_SELECT_, \
140138
_CCCL_PP_EVAL(_CCCL_PP_CHECK, _CCCL_PP_CAT3(_CCCL_PP_EAT_TYPENAME_PROBE_, _Xp)))
141-
# define _CCCL_PP_EAT_TYPENAME_(...) \
142-
_CCCL_PP_EVAL2(_CCCL_PP_EAT_TYPENAME_SELECT_, __VA_ARGS__, ) \
143-
(__VA_ARGS__)
139+
# define _CCCL_PP_EAT_TYPENAME_(...) _CCCL_PP_EVAL2(_CCCL_PP_EAT_TYPENAME_SELECT_, __VA_ARGS__, )(__VA_ARGS__)
144140
# define _CCCL_PP_EAT_TYPENAME_SELECT_0(...) __VA_ARGS__
145141
# define _CCCL_PP_EAT_TYPENAME_SELECT_1(...) _CCCL_PP_CAT3(_CCCL_PP_EAT_TYPENAME_, __VA_ARGS__)
146142
# define _CCCL_PP_EAT_TYPENAME_typename
@@ -178,13 +174,13 @@ namespace __unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-decls
178174
# define _CCCL_CONCEPT_FRAGMENT(_NAME, ...) \
179175
_LIBCUDACXX_HIDE_FROM_ABI auto _NAME##_CCCL_CONCEPT_FRAGMENT_impl_ _CCCL_CONCEPT_FRAGMENT_REQS_##__VA_ARGS__ > { \
180176
} \
181-
template <typename... _As> \
177+
template <class... _As> \
182178
_LIBCUDACXX_HIDE_FROM_ABI char _NAME##_CCCL_CONCEPT_FRAGMENT_( \
183-
__cccl_concept::_Tag<_As...>*, decltype(&_NAME##_CCCL_CONCEPT_FRAGMENT_impl_<_As...>)); \
184-
_LIBCUDACXX_HIDE_FROM_ABI char(&_NAME##_CCCL_CONCEPT_FRAGMENT_(...))[2] /**/
179+
::__cccl_tag<_As...>*, decltype(&_NAME##_CCCL_CONCEPT_FRAGMENT_impl_<_As...>)); \
180+
_LIBCUDACXX_HIDE_FROM_ABI char(&_NAME##_CCCL_CONCEPT_FRAGMENT_(...))[2]
185181
# if defined(_MSC_VER) && !defined(__clang__)
186182
# define _CCCL_CONCEPT_FRAGMENT_TRUE(...) \
187-
__cccl_concept::__is_true<decltype(_CCCL_PP_FOR_EACH(_CCCL_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) void())>()
183+
::__cccl_is_true<decltype(_CCCL_PP_FOR_EACH(_CCCL_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) void())>()
188184
# else
189185
# define _CCCL_CONCEPT_FRAGMENT_TRUE(...) \
190186
!(decltype(_CCCL_PP_FOR_EACH(_CCCL_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) void(), false){})
@@ -194,23 +190,22 @@ namespace __unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-decls
194190
# define _CCCL_CONCEPT_FRAGMENT_REQS_M(_REQ) \
195191
_CCCL_PP_CAT2(_CCCL_CONCEPT_FRAGMENT_REQS_M, _CCCL_PP_IS_PAREN(_REQ)) \
196192
(_REQ),
197-
# define _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_requires(...) __cccl_concept::__cccl_requires<__VA_ARGS__>
198-
# define _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_typename(...) static_cast<__cccl_concept::_Tag<__VA_ARGS__>*>(nullptr)
193+
# define _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_requires(...) ::__cccl_requires<__VA_ARGS__>
194+
# define _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_typename(...) static_cast<::__cccl_tag<__VA_ARGS__>*>(nullptr)
199195
# if _CCCL_COMPILER(GCC, <, 14)
200196
// GCC < 14 can't mangle noexcept expressions, so just check that the
201197
// expression is well-formed.
202198
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70790
203199
# define _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_noexcept(...) __VA_ARGS__
204200
# else
205-
# define _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_noexcept(...) __cccl_concept::__cccl_requires<noexcept(__VA_ARGS__)>
201+
# define _CCCL_CONCEPT_FRAGMENT_REQS_REQUIRES_noexcept(...) ::__cccl_requires<noexcept(__VA_ARGS__)>
206202
# endif
207203
# define _CCCL_CONCEPT_FRAGMENT_REQS_SAME_AS(_REQ) \
208-
__cccl_concept::__cccl_requires< \
209-
_CUDA_VSTD::same_as<_CCCL_PP_CAT4(_CCCL_CONCEPT_FRAGMENT_REQS_SAME_AS_, _REQ) _CCCL_PP_RPAREN>>
204+
::__cccl_requires<_CUDA_VSTD::same_as<_CCCL_PP_CAT4(_CCCL_CONCEPT_FRAGMENT_REQS_SAME_AS_, _REQ) _CCCL_PP_RPAREN>>
210205
# define _CCCL_CONCEPT_FRAGMENT_REQS_SAME_AS__Same_as(...) __VA_ARGS__, decltype _CCCL_PP_LPAREN
211206

212207
# define _CCCL_FRAGMENT(_NAME, ...) \
213-
(1u == sizeof(_NAME##_CCCL_CONCEPT_FRAGMENT_(static_cast<__cccl_concept::_Tag<__VA_ARGS__>*>(nullptr), nullptr)))
208+
(1u == sizeof(_NAME##_CCCL_CONCEPT_FRAGMENT_(static_cast<::__cccl_tag<__VA_ARGS__>*>(nullptr), nullptr)))
214209

215210
# endif
216211

@@ -225,7 +220,7 @@ namespace __unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-decls
225220
// );
226221
//
227222
// Can only be used as the last requirement in a concept definition.
228-
# if defined(__cpp_concepts) && _CCCL_STD_VER >= 2020
223+
# if defined(__cpp_concepts) && _CCCL_STD_VER >= 2020 || defined(_CCCL_DOXYGEN_INVOKED)
229224
# define _CCCL_REQUIRES_EXPR(_TY, ...) requires(__VA_ARGS__) _CCCL_REQUIRES_EXPR_2
230225
# define _CCCL_REQUIRES_EXPR_2(...) {_CCCL_PP_FOR_EACH(_CCCL_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__)}
231226
# else
@@ -249,27 +244,29 @@ namespace __unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-decls
249244
# define _CCCL_REQUIRES_EXPR_EXPAND_TPARAMS(...) _CCCL_PP_FOR_EACH(_CCCL_REQUIRES_EXPR_EXPAND_TPARAM, __VA_ARGS__)
250245

251246
# define _CCCL_REQUIRES_EXPR(_TY, ...) \
252-
__cccl_concept::__requires_expr_impl<struct _CCCL_PP_CAT( \
253-
__cccl_requires_expr_detail_, __LINE__) _CCCL_REQUIRES_EXPR_EXPAND_TPARAMS _TY>:: \
254-
__cccl_is_satisfied(static_cast<__cccl_concept::_Tag<void _CCCL_REQUIRES_EXPR_EXPAND_TPARAMS _TY>*>(nullptr), \
255-
static_cast<void (*)(__VA_ARGS__)>(nullptr)); \
247+
::__cccl_requires_expr_impl< \
248+
struct _CCCL_PP_CAT(__cccl_requires_expr_detail_, __LINE__) _CCCL_REQUIRES_EXPR_EXPAND_TPARAMS \
249+
_TY>::__cccl_is_satisfied(static_cast<::__cccl_tag<void _CCCL_REQUIRES_EXPR_EXPAND_TPARAMS _TY>*>(nullptr), \
250+
static_cast<void (*)(__VA_ARGS__)>(nullptr)); \
256251
struct _CCCL_PP_CAT(__cccl_requires_expr_detail_, __LINE__) \
257252
{ \
258-
using _Self_t = _CCCL_PP_CAT(__cccl_requires_expr_detail_, __LINE__); \
253+
using __cccl_self_t = _CCCL_PP_CAT(__cccl_requires_expr_detail_, __LINE__); \
259254
template <class _CCCL_REQUIRES_EXPR_TPARAMS _TY> \
260-
_LIBCUDACXX_HIDE_FROM_ABI static auto _Well_formed(__VA_ARGS__) _CCCL_REQUIRES_EXPR_2
261-
262-
# define _CCCL_REQUIRES_EXPR_2(...) \
263-
->decltype(_CCCL_PP_FOR_EACH(_CCCL_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) void()) {} \
264-
template <class... Args, class Sig, class = decltype(static_cast<Sig*>(&_Self_t::_Well_formed<Args...>))> \
265-
_LIBCUDACXX_HIDE_FROM_ABI static constexpr bool __cccl_is_satisfied(__cccl_concept::_Tag<Args...>*, Sig*) \
266-
{ \
267-
return true; \
268-
} \
269-
_LIBCUDACXX_HIDE_FROM_ABI static constexpr bool __cccl_is_satisfied(void*, ...) \
270-
{ \
271-
return false; \
272-
} \
255+
_LIBCUDACXX_HIDE_FROM_ABI static auto __cccl_well_formed(__VA_ARGS__) _CCCL_REQUIRES_EXPR_2
256+
257+
# define _CCCL_REQUIRES_EXPR_2(...) \
258+
->decltype(_CCCL_PP_FOR_EACH(_CCCL_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) void()) {} \
259+
template <class... _Args, \
260+
class _Sig, \
261+
class = decltype(static_cast<_Sig*>(&__cccl_self_t::__cccl_well_formed<_Args...>))> \
262+
_LIBCUDACXX_HIDE_FROM_ABI static constexpr bool __cccl_is_satisfied(::__cccl_tag<_Args...>*, _Sig*) \
263+
{ \
264+
return true; \
265+
} \
266+
_LIBCUDACXX_HIDE_FROM_ABI static constexpr bool __cccl_is_satisfied(void*, ...) \
267+
{ \
268+
return false; \
269+
} \
273270
}
274271
# endif
275272

0 commit comments

Comments
 (0)