Skip to content

Commit

Permalink
add a _CCCL_NO_CONCEPTS config macro (#2945)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernhard Manfred Gruber <[email protected]>
  • Loading branch information
ericniebler and bernhardmgruber authored Nov 25, 2024
1 parent db47d38 commit a085ba1
Show file tree
Hide file tree
Showing 42 changed files with 187 additions and 179 deletions.
6 changes: 6 additions & 0 deletions libcudacxx/include/cuda/std/__cccl/dialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
# define _CCCL_IF_CONSTEXPR if constexpr
# define _CCCL_ELSE_IF_CONSTEXPR else if constexpr
#else // ^^^ C++17 ^^^ / vvv C++14 vvv
# define _CCCL_NO_IF_CONSTEXPR
# define _CCCL_IF_CONSTEXPR if
# define _CCCL_ELSE_IF_CONSTEXPR else if
#endif // _CCCL_STD_VER <= 2014
Expand All @@ -104,6 +105,11 @@
# define _CCCL_NO_VARIABLE_TEMPLATES
#endif // _CCCL_STD_VER <= 2011

// concepts are only available from C++20 onwards
#if _CCCL_STD_VER <= 2017 || !defined(__cpp_concepts) || (__cpp_concepts < 201907L)
# define _CCCL_NO_CONCEPTS
#endif // _CCCL_STD_VER <= 2017 || !defined(__cpp_concepts) || (__cpp_concepts < 201907L)

// noexcept function types are only available from C++17 onwards
#if _CCCL_STD_VER >= 2017 && defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510L)
# define _CCCL_FUNCTION_TYPE_NOEXCEPT noexcept
Expand Down
4 changes: 2 additions & 2 deletions libcudacxx/include/cuda/std/__concepts/arithmetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2011
#if !defined(_CCCL_NO_VARIABLE_TEMPLATES)

// [concepts.arithmetic], arithmetic concepts

Expand All @@ -49,7 +49,7 @@ _CCCL_CONCEPT floating_point = _CCCL_TRAIT(is_floating_point, _Tp);
template <class _Tp>
_CCCL_CONCEPT __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value;

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/std/__concepts/assignable.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2017
#if !defined(_CCCL_NO_CONCEPTS)

// [concept.assignable]

Expand All @@ -40,7 +40,7 @@ concept assignable_from =
{ __lhs = _CUDA_VSTD::forward<_Rhs>(__rhs) } -> same_as<_Lhs>;
};

#elif _CCCL_STD_VER > 2011
#elif !defined(_CCCL_NO_VARIABLE_TEMPLATES) // ^^^ !_CCCL_NO_CONCEPTS ^^^

template <class _Lhs, class _Rhs>
_CCCL_CONCEPT_FRAGMENT(
Expand All @@ -53,7 +53,7 @@ _CCCL_CONCEPT_FRAGMENT(
template <class _Lhs, class _Rhs>
_CCCL_CONCEPT assignable_from = _CCCL_FRAGMENT(__assignable_from_, _Lhs, _Rhs);

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/std/__concepts/boolean_testable.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2017
#if !defined(_CCCL_NO_CONCEPTS)

// [concepts.booleantestable]

Expand All @@ -38,7 +38,7 @@ concept __boolean_testable = __boolean_testable_impl<_Tp> && requires(_Tp&& __t)
{ !_CUDA_VSTD::forward<_Tp>(__t) } -> __boolean_testable_impl;
};

#elif _CCCL_STD_VER > 2011
#elif !defined(_CCCL_NO_VARIABLE_TEMPLATES) // ^^^ !_CCCL_NO_CONCEPTS ^^^

template <class _Tp>
_CCCL_CONCEPT __boolean_testable_impl = convertible_to<_Tp, bool>;
Expand All @@ -52,7 +52,7 @@ _CCCL_CONCEPT_FRAGMENT(
template <class _Tp>
_CCCL_CONCEPT __boolean_testable = _CCCL_FRAGMENT(__boolean_testable_, _Tp);

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
4 changes: 2 additions & 2 deletions libcudacxx/include/cuda/std/__concepts/class_or_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2011
#if !defined(_CCCL_NO_VARIABLE_TEMPLATES)

template <class _Tp>
_CCCL_CONCEPT __class_or_enum = _CCCL_TRAIT(is_class, _Tp) || _CCCL_TRAIT(is_union, _Tp) || _CCCL_TRAIT(is_enum, _Tp);
Expand All @@ -39,7 +39,7 @@ template <class _Tp>
_CCCL_CONCEPT __workaround_52970 =
_CCCL_TRAIT(is_class, remove_cvref_t<_Tp>) || _CCCL_TRAIT(is_union, remove_cvref_t<_Tp>);

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2017
#if !defined(_CCCL_NO_CONCEPTS)

// [concept.commonref]

Expand All @@ -38,7 +38,7 @@ concept common_reference_with =
same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>>
&& convertible_to<_Tp, common_reference_t<_Tp, _Up>> && convertible_to<_Up, common_reference_t<_Tp, _Up>>;

#elif _CCCL_STD_VER > 2011
#elif !defined(_CCCL_NO_VARIABLE_TEMPLATES) // ^^^ !_CCCL_NO_CONCEPTS ^^^

template <class _Tp, class _Up>
_CCCL_CONCEPT_FRAGMENT(__common_reference_exists_,
Expand All @@ -58,7 +58,7 @@ _CCCL_CONCEPT_FRAGMENT(
template <class _Tp, class _Up>
_CCCL_CONCEPT common_reference_with = _CCCL_FRAGMENT(__common_reference_with_, _Tp, _Up);

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/std/__concepts/common_with.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2017
#if !defined(_CCCL_NO_CONCEPTS)

// [concept.common]

Expand All @@ -39,7 +39,7 @@ concept common_with = same_as<common_type_t<_Tp, _Up>, common_type_t<_Up, _Tp>>
static_cast<common_type_t<_Tp, _Up>>(_CUDA_VSTD::declval<_Up>());
} && common_reference_with<add_lvalue_reference_t<const _Tp>, add_lvalue_reference_t<const _Up>> && common_reference_with<add_lvalue_reference_t<common_type_t<_Tp, _Up>>, common_reference_t<add_lvalue_reference_t<const _Tp>, add_lvalue_reference_t<const _Up>>>;

#elif _CCCL_STD_VER > 2011
#elif !defined(_CCCL_NO_VARIABLE_TEMPLATES) // ^^^ !_CCCL_NO_CONCEPTS ^^^

template <class _Tp, class _Up>
_CCCL_CONCEPT_FRAGMENT(__common_type_exists_,
Expand Down Expand Up @@ -71,7 +71,7 @@ _CCCL_CONCEPT_FRAGMENT(
template <class _Tp, class _Up>
_CCCL_CONCEPT common_with = _CCCL_FRAGMENT(__common_with_, _Tp, _Up);

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
23 changes: 12 additions & 11 deletions libcudacxx/include/cuda/std/__concepts/concept_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,22 @@ using __cccl_enable_if_t = typename __cccl_select<_Bp>::template type<_Tp>;
template <class _Tp, bool _Bp>
using __cccl_requires_t = typename __cccl_select<_Bp>::template type<_Tp>;

#if (defined(__cpp_concepts) && _CCCL_STD_VER >= 2020) || defined(_CCCL_DOXYGEN_INVOKED)
#if !defined(_CCCL_NO_CONCEPTS) || defined(_CCCL_DOXYGEN_INVOKED)
# define _CCCL_TEMPLATE(...) template <__VA_ARGS__>
# define _CCCL_REQUIRES(...) requires __VA_ARGS__
# define _CCCL_AND &&
# define _CCCL_TRAILING_REQUIRES_AUX_(...) requires __VA_ARGS__
# define _CCCL_TRAILING_REQUIRES(...) ->__VA_ARGS__ _CCCL_TRAILING_REQUIRES_AUX_
#else // ^^^ __cpp_concepts ^^^ / vvv !__cpp_concepts vvv
#else // ^^^ _CCCL_NO_CONCEPTS ^^^ / vvv !_CCCL_NO_CONCEPTS vvv
# define _CCCL_TEMPLATE(...) template <__VA_ARGS__
# define _CCCL_REQUIRES(...) , bool __cccl_true_ = true, __cccl_enable_if_t < __VA_ARGS__ && __cccl_true_, int > = 0 >
# define _CCCL_AND &&__cccl_true_, int > = 0, __cccl_enable_if_t <
# define _CCCL_TRAILING_REQUIRES_AUX_(...) , __VA_ARGS__ >
# define _CCCL_TRAILING_REQUIRES(...) ->__cccl_requires_t < __VA_ARGS__ _CCCL_TRAILING_REQUIRES_AUX_
#endif // !__cpp_concepts
#endif // !defined(_CCCL_NO_CONCEPTS)

#if _CCCL_STD_VER >= 2014
// The following concepts emulation macros need variable template support
#if !defined(_CCCL_NO_VARIABLE_TEMPLATES)

template <class...>
struct __cccl_tag;
Expand Down Expand Up @@ -141,7 +142,7 @@ namespace __cccl_unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-
# define _CCCL_PP_EAT_TYPENAME_SELECT_1(...) _CCCL_PP_CAT3(_CCCL_PP_EAT_TYPENAME_, __VA_ARGS__)
# define _CCCL_PP_EAT_TYPENAME_typename

# if (defined(__cpp_concepts) && _CCCL_STD_VER >= 2020) || defined(_CCCL_DOXYGEN_INVOKED)
# if !defined(_CCCL_NO_CONCEPTS) || defined(_CCCL_DOXYGEN_INVOKED)

# define _CCCL_CONCEPT concept

Expand All @@ -167,7 +168,7 @@ namespace __cccl_unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-

# define _CCCL_FRAGMENT(_NAME, ...) _NAME<__VA_ARGS__>

# else
# else // ^^^ !_CCCL_NO_CONCEPTS ^^^ / vvv _CCCL_NO_CONCEPTS vvv

# define _CCCL_CONCEPT _CCCL_INLINE_VAR constexpr bool

Expand Down Expand Up @@ -207,7 +208,7 @@ namespace __cccl_unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-
# define _CCCL_FRAGMENT(_NAME, ...) \
(1u == sizeof(_NAME##_CCCL_CONCEPT_FRAGMENT_(static_cast<::__cccl_tag<__VA_ARGS__>*>(nullptr), nullptr)))

# endif
# endif // ^^^ _CCCL_NO_CONCEPTS ^^^

////////////////////////////////////////////////////////////////////////////////
// _CCCL_REQUIRES_EXPR
Expand All @@ -220,10 +221,10 @@ namespace __cccl_unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-
// );
//
// Can only be used as the last requirement in a concept definition.
# if defined(__cpp_concepts) && _CCCL_STD_VER >= 2020 || defined(_CCCL_DOXYGEN_INVOKED)
# if !defined(_CCCL_NO_CONCEPTS) || defined(_CCCL_DOXYGEN_INVOKED)
# define _CCCL_REQUIRES_EXPR(_TY, ...) requires(__VA_ARGS__) _CCCL_REQUIRES_EXPR_2
# define _CCCL_REQUIRES_EXPR_2(...) {_CCCL_PP_FOR_EACH(_CCCL_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__)}
# else
# else // ^^^ !_CCCL_NO_CONCEPTS ^^^ / vvv _CCCL_NO_CONCEPTS vvv
# define _CCCL_REQUIRES_EXPR_TPARAM_PROBE_variadic _CCCL_PP_PROBE(~)
# define _CCCL_REQUIRES_EXPR_TPARAM_variadic

Expand Down Expand Up @@ -268,8 +269,8 @@ namespace __cccl_unqualified_cuda_std = _CUDA_VSTD; // NOLINT(misc-unused-alias-
return false; \
} \
}
# endif
# endif // ^^^ _CCCL_NO_CONCEPTS ^^^

#endif // _CCCL_STD_VER >= 2014
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES ^^^

#endif //_CUDA___CONCEPTS
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/std/__concepts/constructible.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2017
#if !defined(_CCCL_NO_CONCEPTS)

// [concept.constructible]
template <class _Tp, class... _Args>
Expand All @@ -52,7 +52,7 @@ concept copy_constructible =
&& constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> && constructible_from<_Tp, const _Tp>
&& convertible_to<const _Tp, _Tp>;

#elif _CCCL_STD_VER > 2011
#elif !defined(_CCCL_NO_VARIABLE_TEMPLATES) // ^^^ !_CCCL_NO_CONCEPTS ^^^

template <class _Tp, class... _Args>
_CCCL_CONCEPT_FRAGMENT(__constructible_from_,
Expand Down Expand Up @@ -96,7 +96,7 @@ _CCCL_CONCEPT_FRAGMENT(
template <class _Tp>
_CCCL_CONCEPT copy_constructible = _CCCL_FRAGMENT(__copy_constructible_, _Tp);

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/std/__concepts/convertible_to.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD

// [concept.convertible]

#if _CCCL_STD_VER >= 2020
#if !defined(_CCCL_NO_CONCEPTS)

template <class _From, class _To>
concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(_CUDA_VSTD::declval<_From>()); };

#elif _CCCL_STD_VER >= 2014 // ^^^ C++20 ^^^ / vvv C++14/17 vvv
#elif !defined(_CCCL_NO_VARIABLE_TEMPLATES) // ^^^ !_CCCL_NO_CONCEPTS ^^^

# if _CCCL_COMPILER(MSVC)
_CCCL_NV_DIAG_SUPPRESS(1211) // nonstandard cast to array type ignored
Expand All @@ -60,7 +60,7 @@ _CCCL_NV_DIAG_DEFAULT(1211) // nonstandard cast to array type ignored
# endif // _CCCL_COMPILER(MSVC)
_CCCL_NV_DIAG_DEFAULT(171) // invalid type conversion, e.g. [with _From=int **, _To=const int *const *]

#endif // _CCCL_STD_VER >= 2014
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES ^^^

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/std/__concepts/copyable.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2017
#if !defined(_CCCL_NO_CONCEPTS)

// [concepts.object]

template <class _Tp>
concept copyable = copy_constructible<_Tp> && movable<_Tp> && assignable_from<_Tp&, _Tp&>
&& assignable_from<_Tp&, const _Tp&> && assignable_from<_Tp&, const _Tp>;

#elif _CCCL_STD_VER > 2011
#elif !defined(_CCCL_NO_VARIABLE_TEMPLATES) // ^^^ !_CCCL_NO_CONCEPTS ^^^

template <class _Tp>
_CCCL_CONCEPT_FRAGMENT(
Expand All @@ -49,7 +49,7 @@ _CCCL_CONCEPT_FRAGMENT(
template <class _Tp>
_CCCL_CONCEPT copyable = _CCCL_FRAGMENT(__copyable_, _Tp);

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/std/__concepts/derived_from.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2017
#if !defined(_CCCL_NO_CONCEPTS)

// [concept.derived]

template <class _Dp, class _Bp>
concept derived_from = is_base_of_v<_Bp, _Dp> && is_convertible_v<const volatile _Dp*, const volatile _Bp*>;

#elif _CCCL_STD_VER > 2011
#elif !defined(_CCCL_NO_VARIABLE_TEMPLATES) // ^^^ !_CCCL_NO_CONCEPTS ^^^

template <class _Dp, class _Bp>
_CCCL_CONCEPT_FRAGMENT(
Expand All @@ -46,7 +46,7 @@ _CCCL_CONCEPT_FRAGMENT(
template <class _Dp, class _Bp>
_CCCL_CONCEPT derived_from = _CCCL_FRAGMENT(__derived_from_, _Dp, _Bp);

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
4 changes: 2 additions & 2 deletions libcudacxx/include/cuda/std/__concepts/destructible.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2011
#if !defined(_CCCL_NO_VARIABLE_TEMPLATES)

# if _CCCL_COMPILER(MSVC)

Expand Down Expand Up @@ -69,7 +69,7 @@ _CCCL_CONCEPT destructible = __destructible<_Tp>;

# endif // !_CCCL_COMPILER(MSVC)

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
4 changes: 2 additions & 2 deletions libcudacxx/include/cuda/std/__concepts/different_from.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER > 2011
#if !defined(_CCCL_NO_VARIABLE_TEMPLATES)

template <class _Tp, class _Up>
_CCCL_CONCEPT __different_from = !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;

#endif // _CCCL_STD_VER > 2011
#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
Loading

0 comments on commit a085ba1

Please sign in to comment.