11// SPDX-License-Identifier: BSD-3-Clause
2- /* Copyright 2016-2020 , Intel Corporation */
2+ /* Copyright 2016-2021 , Intel Corporation */
33
44/* *
55 * @file
1010#define LIBPMEMOBJ_CPP_INTEGER_SEQUENCE_HPP
1111
1212#include < cstddef>
13+ #include < type_traits>
1314
1415namespace pmem
1516{
@@ -30,46 +31,49 @@ struct integer_sequence {
3031template <size_t ... Indices>
3132using index_sequence = integer_sequence<size_t , Indices...>;
3233
33- /*
34- * Empty base class.
35- *
36- * Subject of empty base optimization.
37- */
38- template <typename T, T I, typename ... Types>
34+ template <typename T, T N, typename Enable, T... I>
3935struct make_integer_seq_impl ;
4036
4137/*
42- * Class ending recursive variadic template peeling.
38+ * Helper for make_integer_sequence, specialization for N == 0 (end of
39+ * recursion).
4340 */
44- template <typename T, T I, T... Indices>
45- struct make_integer_seq_impl <T, I, integer_sequence<T, Indices...>> {
46- typedef integer_sequence<T, Indices...> type;
41+ template <typename T, T N, T... I>
42+ struct make_integer_seq_impl <T, N, typename std::enable_if<N == 0 >::type,
43+ I...> {
44+ using type = integer_sequence<T, I...>;
4745};
4846
4947/*
50- * Recursively create index while peeling off the types .
48+ * Helper for make_integer_sequence, base case .
5149 */
52- template <typename N, N I, N... Indices, typename T, typename ... Types>
53- struct make_integer_seq_impl <N, I, integer_sequence<N, Indices...>, T,
54- Types...> {
55- typedef typename make_integer_seq_impl<
56- N, I + 1 , integer_sequence<N, Indices..., I>, Types...>::type
57- type;
50+ template <typename T, T N, T... I>
51+ struct make_integer_seq_impl <T, N, typename std::enable_if<N != 0 >::type,
52+ I...> {
53+ using type = typename make_integer_seq_impl<T, N - 1 , void , N - 1 ,
54+ I...>::type;
5855};
5956
6057/*
61- * Make index sequence entry point .
58+ * Implementation of std::make_integer_sequence which works with C++11 .
6259 */
63- template <typename ... Types>
64- using make_index_sequence =
65- make_integer_seq_impl<size_t , 0 , integer_sequence<size_t >, Types...>;
60+ template <typename T, T N>
61+ using make_integer_sequence = typename make_integer_seq_impl<T, N, void >::type;
6662
6763/*
64+ * Implementation of std::make_index_sequence which works with C++11.
65+ */
66+ template <size_t N>
67+ using make_index_sequence = make_integer_sequence<size_t , N>;
68+
69+ /*
70+ * Implementation of std::index_sequence_for which works with C++11.
71+ *
6872 * A helper alias template to convert any type parameter pack into an index
69- * sequence of the same length. Analog of std::index_sequence_for.
73+ * sequence of the same length.
7074 */
7175template <class ... Types>
72- using index_sequence_for = typename make_index_sequence<Types ...>::type ;
76+ using index_sequence_for = make_index_sequence<sizeof ...(Types)> ;
7377
7478} /* namespace detail */
7579
0 commit comments