Skip to content

Commit c672659

Browse files
Make integer sequence et al. available in C++11 (#1859)
* Make integer_sequence et al. available in C++11 So Thrust can depend on it. Co-authored-by: Michael Schellenberger Costa <[email protected]>
1 parent 6647773 commit c672659

File tree

11 files changed

+11
-123
lines changed

11 files changed

+11
-123
lines changed

docs/thrust/api_docs/utility/type_traits.rst

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Type Traits
77
:glob:
88
:maxdepth: 1
99

10-
${repo_docs_api_path}/*struct*integer__sequence*
1110
${repo_docs_api_path}/*struct*proclaim__contiguous__iterator*
1211
${repo_docs_api_path}/*struct*conjunction*
1312
${repo_docs_api_path}/*struct*disjunction*

libcudacxx/include/cuda/std/__utility/integer_sequence.h

+6-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct __integer_sequence
3939
using __to_tuple_indices = __tuple_indices<(_Values + _Sp)...>;
4040
};
4141

42-
#if !__has_builtin(__make_integer_seq) || defined(_LIBCUDACXX_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
42+
#ifndef _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
4343

4444
namespace __detail
4545
{
@@ -170,9 +170,9 @@ struct __parity<7>
170170

171171
} // namespace __detail
172172

173-
#endif // !__has_builtin(__make_integer_seq) || defined(_LIBCUDACXX_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
173+
#endif // !_LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
174174

175-
#if __has_builtin(__make_integer_seq)
175+
#ifdef _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
176176
template <size_t _Ep, size_t _Sp>
177177
using __make_indices_imp =
178178
typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>;
@@ -182,8 +182,6 @@ using __make_indices_imp = typename __detail::__make<_Ep - _Sp>::type::template
182182

183183
#endif
184184

185-
#if _CCCL_STD_VER > 2011
186-
187185
template <class _Tp, _Tp... _Ip>
188186
struct _LIBCUDACXX_TEMPLATE_VIS integer_sequence
189187
{
@@ -198,12 +196,12 @@ struct _LIBCUDACXX_TEMPLATE_VIS integer_sequence
198196
template <size_t... _Ip>
199197
using index_sequence = integer_sequence<size_t, _Ip...>;
200198

201-
# if __has_builtin(__make_integer_seq) && !defined(_LIBCUDACXX_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
199+
#ifdef _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
202200

203201
template <class _Tp, _Tp _Ep>
204202
using __make_integer_sequence _LIBCUDACXX_NODEBUG_TYPE = __make_integer_seq<integer_sequence, _Tp, _Ep>;
205203

206-
# else
204+
#else // _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
207205

208206
template <typename _Tp, _Tp _Np>
209207
using __make_integer_sequence_unchecked _LIBCUDACXX_NODEBUG_TYPE =
@@ -222,7 +220,7 @@ struct __make_integer_sequence_checked
222220
template <class _Tp, _Tp _Ep>
223221
using __make_integer_sequence _LIBCUDACXX_NODEBUG_TYPE = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
224222

225-
# endif
223+
#endif // _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
226224

227225
template <class _Tp, _Tp _Np>
228226
using make_integer_sequence = __make_integer_sequence<_Tp, _Np>;
@@ -233,8 +231,6 @@ using make_index_sequence = make_integer_sequence<size_t, _Np>;
233231
template <class... _Tp>
234232
using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
235233

236-
#endif // _CCCL_STD_VER > 2011
237-
238234
_LIBCUDACXX_END_NAMESPACE_STD
239235

240236
#endif // _LIBCUDACXX___UTILITY_INTEGER_SEQUENCE_H

libcudacxx/include/cuda/std/detail/libcxx/include/__config

+4
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,10 @@ typedef unsigned int char32_t;
12841284
# define _LIBCUDACXX_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
12851285
# endif
12861286

1287+
# if __check_builtin(make_integer_seq) && !defined(_LIBCUDACXX_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
1288+
# define _LIBCUDACXX_HAS_MAKE_INTEGER_SEQ
1289+
# endif
1290+
12871291
# define _LIBCUDACXX_DECLARE_STRONG_ENUM(x) enum class _LIBCUDACXX_ENUM_VIS x
12881292
# define _LIBCUDACXX_DECLARE_STRONG_ENUM_EPILOG(x)
12891293

libcudacxx/test/libcudacxx/std/utilities/intseq/intseq.general/integer_seq.pass.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
// UNSUPPORTED: c++03, c++11
1110
// <utility>
1211

1312
// class make_integer_sequence

libcudacxx/test/libcudacxx/std/utilities/intseq/intseq.intseq/integer_seq.compile.fail.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
// UNSUPPORTED: c++03, c++11
11-
1210
// <utility>
1311

1412
// template<class T, T... I>

libcudacxx/test/libcudacxx/std/utilities/intseq/intseq.intseq/integer_seq.pass.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
// UNSUPPORTED: c++03, c++11
1110
// <utility>
1211

1312
// template<class T, T... I>

libcudacxx/test/libcudacxx/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// template<class T, T N>
1313
// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
1414

15-
// UNSUPPORTED: c++03, c++11
16-
1715
// This test hangs during recursive template instantiation with libstdc++
1816
// UNSUPPORTED: stdlib=libstdc++
1917

libcudacxx/test/libcudacxx/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// template<class T, T N>
1313
// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
1414

15-
// UNSUPPORTED: c++03, c++11
16-
1715
#include <cuda/std/cassert>
1816
#include <cuda/std/type_traits>
1917
#include <cuda/std/utility>

libcudacxx/test/libcudacxx/std/utilities/intseq/intseq.make/make_integer_seq_fallback.compile.fail.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// template<class T, T N>
1313
// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
1414

15-
// UNSUPPORTED: c++03, c++11
16-
1715
// This test hangs during recursive template instantiation with libstdc++
1816
// UNSUPPORTED: stdlib=libstdc++
1917

libcudacxx/test/libcudacxx/std/utilities/intseq/intseq.make/make_integer_seq_fallback.pass.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// template<class T, T N>
1313
// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
1414

15-
// UNSUPPORTED: c++03, c++11
16-
1715
#define _LIBCUDACXX_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE
1816
#include "make_integer_seq.pass.cpp"
1917
#include "test_macros.h"

thrust/thrust/type_traits/integer_sequence.h

+1-100
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 NVIDIA Corporation
2+
* Copyright 2008-2024 NVIDIA Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,23 +57,8 @@ THRUST_NAMESPACE_BEGIN
5757
* integer_sequence_push_back \see <a
5858
* href="https://en.cppreference.com/w/cpp/utility/integer_sequence"><tt>std::integer_sequence</tt></a>
5959
*/
60-
#if _CCCL_STD_VER >= 2014
6160
template <typename T, T... Is>
6261
using integer_sequence = ::cuda::std::integer_sequence<T, Is...>;
63-
#else
64-
template <typename T, T... Is>
65-
struct integer_sequence
66-
{
67-
using type = integer_sequence;
68-
using value_type = T;
69-
using size_type = ::cuda::std::size_t;
70-
71-
_CCCL_HOST_DEVICE static constexpr size_type size() noexcept
72-
{
73-
return sizeof...(Is);
74-
}
75-
};
76-
#endif
7762

7863
///////////////////////////////////////////////////////////////////////////////
7964

@@ -90,46 +75,8 @@ struct integer_sequence
9075
* \see integer_sequence_push_back
9176
* \see <a href="https://en.cppreference.com/w/cpp/utility/integer_sequence"><tt>std::index_sequence</tt></a>
9277
*/
93-
#if _CCCL_STD_VER >= 2014
9478
template <::cuda::std::size_t... Is>
9579
using index_sequence = ::cuda::std::index_sequence<Is...>;
96-
#else
97-
template <::cuda::std::size_t... Is>
98-
using index_sequence = integer_sequence<::cuda::std::size_t, Is...>;
99-
#endif
100-
101-
#if _CCCL_STD_VER < 2014
102-
/*! \cond
103-
*/
104-
105-
namespace detail
106-
{
107-
108-
/*! \brief Create a new \c integer_sequence containing the elements of \c
109-
* Sequence0 followed by the elements of \c Sequence1. \c Sequence0::size() is
110-
* added to each element from \c Sequence1 in the new sequence.
111-
*
112-
* \see integer_sequence
113-
* \see index_sequence
114-
* \see make_reversed_integer_sequence
115-
* \see make_index_sequence
116-
* \see make_reversed_index_sequence
117-
* \see merge_and_renumber_reversed_integer_sequences_impl
118-
*/
119-
template <typename Sequence0, typename Sequence1>
120-
struct merge_and_renumber_integer_sequences_impl;
121-
template <typename Sequence0, typename Sequence1>
122-
using merge_and_renumber_integer_sequences =
123-
typename merge_and_renumber_integer_sequences_impl<Sequence0, Sequence1>::type;
124-
125-
template <typename T, ::cuda::std::size_t N>
126-
struct make_integer_sequence_impl;
127-
128-
} // namespace detail
129-
130-
/*! \endcond
131-
*/
132-
#endif
13380

13481
/*! \brief Create a new \c integer_sequence with elements
13582
* <tt>0, 1, 2, ..., N - 1</tt> of type \c T.
@@ -141,49 +88,8 @@ struct make_integer_sequence_impl;
14188
* \see make_reversed_index_sequence
14289
* \see <a href="https://en.cppreference.com/w/cpp/utility/integer_sequence"><tt>std::make_integer_sequence</tt></a>
14390
*/
144-
#if _CCCL_STD_VER >= 2014
14591
template <typename T, ::cuda::std::size_t N>
14692
using make_integer_sequence = ::cuda::std::make_integer_sequence<T, N>;
147-
#else
148-
template <typename T, ::cuda::std::size_t N>
149-
using make_integer_sequence = typename detail::make_integer_sequence_impl<T, N>::type;
150-
151-
/*! \cond
152-
*/
153-
154-
namespace detail
155-
{
156-
157-
template <typename T, T... Is0, T... Is1>
158-
struct merge_and_renumber_integer_sequences_impl<integer_sequence<T, Is0...>, integer_sequence<T, Is1...>>
159-
{
160-
using type = integer_sequence<T, Is0..., (sizeof...(Is0) + Is1)...>;
161-
};
162-
163-
template <typename T, ::cuda::std::size_t N>
164-
struct make_integer_sequence_impl
165-
{
166-
using type =
167-
merge_and_renumber_integer_sequences<make_integer_sequence<T, N / 2>, make_integer_sequence<T, N - N / 2>>;
168-
};
169-
170-
template <typename T>
171-
struct make_integer_sequence_impl<T, 0>
172-
{
173-
using type = integer_sequence<T>;
174-
};
175-
176-
template <typename T>
177-
struct make_integer_sequence_impl<T, 1>
178-
{
179-
using type = integer_sequence<T, 0>;
180-
};
181-
182-
} // namespace detail
183-
184-
/*! \endcond
185-
*/
186-
#endif
18793

18894
///////////////////////////////////////////////////////////////////////////////
18995

@@ -198,13 +104,8 @@ struct make_integer_sequence_impl<T, 1>
198104
* \see make_reversed_index_sequence
199105
* \see <a href="https://en.cppreference.com/w/cpp/utility/integer_sequence"><tt>std::make_index_sequence</tt></a>
200106
*/
201-
#if _CCCL_STD_VER >= 2014
202107
template <::cuda::std::size_t N>
203108
using make_index_sequence = ::cuda::std::make_index_sequence<N>;
204-
#else
205-
template <::cuda::std::size_t N>
206-
using make_index_sequence = make_integer_sequence<::cuda::std::size_t, N>;
207-
#endif
208109

209110
///////////////////////////////////////////////////////////////////////////////
210111

0 commit comments

Comments
 (0)