Skip to content

Commit

Permalink
Make bool_constant available in C++11 (NVIDIA#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jul 22, 2024
1 parent 496d88d commit e61bafe
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion libcudacxx/include/cuda/std/__tuple_dir/sfinae_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct __tuple_sfinae_base
{};

template <class... _Tp, class... _Up>
struct __test_size<__tuple_types<_Tp...>, __tuple_types<_Up...>> : _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>
struct __test_size<__tuple_types<_Tp...>, __tuple_types<_Up...>> : bool_constant<sizeof...(_Tp) == sizeof...(_Up)>
{};

template <template <class, class...> class, class _Tp, class _Up, bool = __test_size<_Tp, _Up>::value>
Expand Down
11 changes: 3 additions & 8 deletions libcudacxx/include/cuda/std/__type_traits/integral_constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,13 @@ typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;

template <bool _Val>
using _BoolConstant _LIBCUDACXX_NODEBUG_TYPE = integral_constant<bool, _Val>;
using _BoolConstant _LIBCUDACXX_DEPRECATED _LIBCUDACXX_NODEBUG_TYPE = integral_constant<bool, _Val>;

#if _CCCL_STD_VER > 2011
template <bool __b>
using bool_constant = integral_constant<bool, __b>;
#endif

#if _CCCL_STD_VER > 2011
# define _LIBCUDACXX_BOOL_CONSTANT(__b) bool_constant<(__b)>
#else
# define _LIBCUDACXX_BOOL_CONSTANT(__b) integral_constant<bool, (__b)>
#endif
// deprecated [Since 2.7.0]
#define _LIBCUDACXX_BOOL_CONSTANT(__b) bool_constant<(__b)>

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
10 changes: 5 additions & 5 deletions libcudacxx/include/cuda/std/__type_traits/is_same.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD
#if defined(_LIBCUDACXX_IS_SAME) && !defined(_LIBCUDACXX_USE_IS_SAME_FALLBACK)

template <class _Tp, class _Up>
struct _LIBCUDACXX_TEMPLATE_VIS is_same : _BoolConstant<_LIBCUDACXX_IS_SAME(_Tp, _Up)>
struct _LIBCUDACXX_TEMPLATE_VIS is_same : bool_constant<_LIBCUDACXX_IS_SAME(_Tp, _Up)>
{};

# if _CCCL_STD_VER > 2011 && !defined(_LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES)
Expand All @@ -43,10 +43,10 @@ _LIBCUDACXX_INLINE_VAR constexpr bool is_same_v = _LIBCUDACXX_IS_SAME(_Tp, _Up);
// (such as in a dependent return type).

template <class _Tp, class _Up>
using _IsSame = _BoolConstant<_LIBCUDACXX_IS_SAME(_Tp, _Up)>;
using _IsSame = bool_constant<_LIBCUDACXX_IS_SAME(_Tp, _Up)>;

template <class _Tp, class _Up>
using _IsNotSame = _BoolConstant<!_LIBCUDACXX_IS_SAME(_Tp, _Up)>;
using _IsNotSame = bool_constant<!_LIBCUDACXX_IS_SAME(_Tp, _Up)>;

#else

Expand All @@ -70,10 +70,10 @@ _LIBCUDACXX_INLINE_VAR constexpr bool is_same_v = is_same<_Tp, _Up>::value;
// (such as in a dependent return type).

template <class _Tp, class _Up>
using _IsSame = _BoolConstant<is_same<_Tp, _Up>::value>;
using _IsSame = bool_constant<is_same<_Tp, _Up>::value>;

template <class _Tp, class _Up>
using _IsNotSame = _BoolConstant<!is_same<_Tp, _Up>::value>;
using _IsNotSame = bool_constant<!is_same<_Tp, _Up>::value>;

#endif // defined(_LIBCUDACXX_IS_SAME) && !defined(_LIBCUDACXX_USE_IS_SAME_FALLBACK)

Expand Down
2 changes: 1 addition & 1 deletion libcudacxx/include/cuda/std/__type_traits/is_signed.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ _LIBCUDACXX_INLINE_VAR constexpr bool is_signed_v = _LIBCUDACXX_IS_SIGNED(_Tp);
#else

template <class _Tp, bool = is_integral<_Tp>::value>
struct __libcpp_is_signed_impl : public _BoolConstant<(_Tp(-1) < _Tp(0))>
struct __libcpp_is_signed_impl : public bool_constant<(_Tp(-1) < _Tp(0))>
{};

template <class _Tp>
Expand Down
2 changes: 1 addition & 1 deletion libcudacxx/include/cuda/std/__type_traits/is_unsigned.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ _LIBCUDACXX_INLINE_VAR constexpr bool is_unsigned_v = _LIBCUDACXX_IS_UNSIGNED(_T
#else

template <class _Tp, bool = is_integral<_Tp>::value>
struct __libcpp_is_unsigned_impl : public _BoolConstant<(_Tp(0) < _Tp(-1))>
struct __libcpp_is_unsigned_impl : public bool_constant<(_Tp(0) < _Tp(-1))>
{};

template <class _Tp>
Expand Down
2 changes: 1 addition & 1 deletion libcudacxx/include/cuda/std/__type_traits/negation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
_LIBCUDACXX_BEGIN_NAMESPACE_STD

template <class _Pred>
struct _Not : _BoolConstant<!_Pred::value>
struct _Not : bool_constant<!_Pred::value>
{};

#if _CCCL_STD_VER > 2011
Expand Down
8 changes: 4 additions & 4 deletions libcudacxx/include/cuda/std/detail/libcxx/include/iterator
Original file line number Diff line number Diff line change
Expand Up @@ -740,22 +740,22 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
_LIBCUDACXX_BEGIN_NAMESPACE_STD

template <class _Iter>
struct __libcpp_is_trivial_iterator : public _LIBCUDACXX_BOOL_CONSTANT(is_pointer<_Iter>::value)
struct __libcpp_is_trivial_iterator : public bool_constant<is_pointer<_Iter>::value>
{};

template <class _Iter>
struct __libcpp_is_trivial_iterator<move_iterator<_Iter>>
: public _LIBCUDACXX_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value)
: public bool_constant<__libcpp_is_trivial_iterator<_Iter>::value>
{};

template <class _Iter>
struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter>>
: public _LIBCUDACXX_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value)
: public bool_constant<__libcpp_is_trivial_iterator<_Iter>::value>
{};

template <class _Iter>
struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter>>
: public _LIBCUDACXX_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value)
: public bool_constant<__libcpp_is_trivial_iterator<_Iter>::value>
{};

_LIBCUDACXX_END_NAMESPACE_STD
Expand Down
13 changes: 6 additions & 7 deletions libcudacxx/include/cuda/std/detail/libcxx/include/ratio
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,11 @@ using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type;
// ratio_equal

template <class _R1, class _R2>
struct _LIBCUDACXX_TEMPLATE_VIS ratio_equal
: public _LIBCUDACXX_BOOL_CONSTANT((_R1::num == _R2::num && _R1::den == _R2::den))
struct _LIBCUDACXX_TEMPLATE_VIS ratio_equal : public bool_constant<(_R1::num == _R2::num && _R1::den == _R2::den)>
{};

template <class _R1, class _R2>
struct _LIBCUDACXX_TEMPLATE_VIS ratio_not_equal : public _LIBCUDACXX_BOOL_CONSTANT((!ratio_equal<_R1, _R2>::value))
struct _LIBCUDACXX_TEMPLATE_VIS ratio_not_equal : public bool_constant<(!ratio_equal<_R1, _R2>::value)>
{};

// ratio_less
Expand Down Expand Up @@ -440,19 +439,19 @@ struct __ratio_less<_R1, _R2, -1LL, -1LL>
};

template <class _R1, class _R2>
struct _LIBCUDACXX_TEMPLATE_VIS ratio_less : public _LIBCUDACXX_BOOL_CONSTANT((__ratio_less<_R1, _R2>::value))
struct _LIBCUDACXX_TEMPLATE_VIS ratio_less : public bool_constant<(__ratio_less<_R1, _R2>::value)>
{};

template <class _R1, class _R2>
struct _LIBCUDACXX_TEMPLATE_VIS ratio_less_equal : public _LIBCUDACXX_BOOL_CONSTANT((!ratio_less<_R2, _R1>::value))
struct _LIBCUDACXX_TEMPLATE_VIS ratio_less_equal : public bool_constant<(!ratio_less<_R2, _R1>::value)>
{};

template <class _R1, class _R2>
struct _LIBCUDACXX_TEMPLATE_VIS ratio_greater : public _LIBCUDACXX_BOOL_CONSTANT((ratio_less<_R2, _R1>::value))
struct _LIBCUDACXX_TEMPLATE_VIS ratio_greater : public bool_constant<(ratio_less<_R2, _R1>::value)>
{};

template <class _R1, class _R2>
struct _LIBCUDACXX_TEMPLATE_VIS ratio_greater_equal : public _LIBCUDACXX_BOOL_CONSTANT((!ratio_less<_R1, _R2>::value))
struct _LIBCUDACXX_TEMPLATE_VIS ratio_greater_equal : public bool_constant<(!ratio_less<_R1, _R2>::value)>
{};

template <class _R1, class _R2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

int main(int, char**)
{
#if TEST_STD_VER > 2011
typedef cuda::std::bool_constant<true> _t;
static_assert(_t::value, "");
static_assert((cuda::std::is_same<_t::value_type, bool>::value), "");
Expand All @@ -29,7 +28,6 @@ int main(int, char**)
static_assert((cuda::std::is_same<_f::value_type, bool>::value), "");
static_assert((cuda::std::is_same<_f::type, _f>::value), "");
static_assert((_f() == false), "");
#endif

return 0;
}

0 comments on commit e61bafe

Please sign in to comment.