Commit 8843e8e2 by Dino Radakovic Committed by Copybara-Service

`absl/utility`: Delete C++11-compatible `integer_sequence` and friends

Abseil does not support C++11 anymore: https://github.com/google/oss-policies-info/blob/b842c39db88e6569dfe2cf98be434b03507cb503/foundational-cxx-support-matrix.md

NOTE: This is a breaking change because `std::integer_sequence<T>` requires `std::is_integral_v<T>`, but `absl::integer_sequence<T>` does not.

Unit tests will be deleted in a follow-up.

PiperOrigin-RevId: 589908215
Change-Id: I57a81e4451840304d5fba60bef286e81e024af9c
parent 55621d1a
...@@ -12,17 +12,12 @@ ...@@ -12,17 +12,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
// This header file contains C++11 versions of standard <utility> header // This header file contains C++14 versions of standard <utility> header
// abstractions available within C++14 and C++17, and are designed to be drop-in // abstractions available within C++17, and are designed to be drop-in
// replacement for code compliant with C++14 and C++17. // replacement for code compliant with C++14 and C++17.
// //
// The following abstractions are defined: // The following abstractions are defined:
// //
// * integer_sequence<T, Ints...> == std::integer_sequence<T, Ints...>
// * index_sequence<Ints...> == std::index_sequence<Ints...>
// * make_integer_sequence<T, N> == std::make_integer_sequence<T, N>
// * make_index_sequence<N> == std::make_index_sequence<N>
// * index_sequence_for<Ts...> == std::index_sequence_for<Ts...>
// * apply<Functor, Tuple> == std::apply<Functor, Tuple> // * apply<Functor, Tuple> == std::apply<Functor, Tuple>
// * exchange<T> == std::exchange<T> // * exchange<T> == std::exchange<T>
// * make_from_tuple<T> == std::make_from_tuple<T> // * make_from_tuple<T> == std::make_from_tuple<T>
...@@ -33,7 +28,6 @@ ...@@ -33,7 +28,6 @@
// //
// References: // References:
// //
// https://en.cppreference.com/w/cpp/utility/integer_sequence
// https://en.cppreference.com/w/cpp/utility/apply // https://en.cppreference.com/w/cpp/utility/apply
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html
...@@ -53,68 +47,18 @@ ...@@ -53,68 +47,18 @@
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
// integer_sequence // Historical note: Abseil once provided implementations of these
// // abstractions for platforms that had not yet provided them. Those
// Class template representing a compile-time integer sequence. An instantiation // platforms are no longer supported. New code should simply use the
// of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its // the ones from std directly.
// type through its template arguments (which is a common need when using std::index_sequence;
// working with C++11 variadic templates). `absl::integer_sequence` is designed using std::index_sequence_for;
// to be a drop-in replacement for C++14's `std::integer_sequence`. using std::integer_sequence;
// using std::make_index_sequence;
// Example: using std::make_integer_sequence;
//
// template< class T, T... Ints >
// void user_function(integer_sequence<T, Ints...>);
//
// int main()
// {
// // user_function's `T` will be deduced to `int` and `Ints...`
// // will be deduced to `0, 1, 2, 3, 4`.
// user_function(make_integer_sequence<int, 5>());
// }
template <typename T, T... Ints>
struct integer_sequence {
using value_type = T;
static constexpr size_t size() noexcept { return sizeof...(Ints); }
};
// index_sequence
//
// A helper template for an `integer_sequence` of `size_t`,
// `absl::index_sequence` is designed to be a drop-in replacement for C++14's
// `std::index_sequence`.
template <size_t... Ints>
using index_sequence = integer_sequence<size_t, Ints...>;
namespace utility_internal { namespace utility_internal {
template <typename Seq, size_t SeqSize, size_t Rem>
struct Extend;
// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency.
template <typename T, T... Ints, size_t SeqSize>
struct Extend<integer_sequence<T, Ints...>, SeqSize, 0> {
using type = integer_sequence<T, Ints..., (Ints + SeqSize)...>;
};
template <typename T, T... Ints, size_t SeqSize>
struct Extend<integer_sequence<T, Ints...>, SeqSize, 1> {
using type = integer_sequence<T, Ints..., (Ints + SeqSize)..., 2 * SeqSize>;
};
// Recursion helper for 'make_integer_sequence<T, N>'.
// 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'.
template <typename T, size_t N>
struct Gen {
using type =
typename Extend<typename Gen<T, N / 2>::type, N / 2, N % 2>::type;
};
template <typename T>
struct Gen<T, 0> {
using type = integer_sequence<T>;
};
template <typename T> template <typename T>
struct InPlaceTypeTag { struct InPlaceTypeTag {
explicit InPlaceTypeTag() = delete; explicit InPlaceTypeTag() = delete;
...@@ -131,32 +75,6 @@ struct InPlaceIndexTag { ...@@ -131,32 +75,6 @@ struct InPlaceIndexTag {
} // namespace utility_internal } // namespace utility_internal
// Compile-time sequences of integers
// make_integer_sequence
//
// This template alias is equivalent to
// `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in
// replacement for C++14's `std::make_integer_sequence`.
template <typename T, T N>
using make_integer_sequence = typename utility_internal::Gen<T, N>::type;
// make_index_sequence
//
// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`,
// and is designed to be a drop-in replacement for C++14's
// `std::make_index_sequence`.
template <size_t N>
using make_index_sequence = make_integer_sequence<size_t, N>;
// index_sequence_for
//
// Converts a typename pack into an index sequence of the same length, and
// is designed to be a drop-in replacement for C++14's
// `std::index_sequence_for()`
template <typename... Ts>
using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
// Tag types // Tag types
#ifdef ABSL_USES_STD_OPTIONAL #ifdef ABSL_USES_STD_OPTIONAL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment