PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
integer_sequence.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2016-2021, Intel Corporation */
3 
9 #ifndef LIBPMEMOBJ_CPP_INTEGER_SEQUENCE_HPP
10 #define LIBPMEMOBJ_CPP_INTEGER_SEQUENCE_HPP
11 
12 #include <cstddef>
13 #include <type_traits>
14 
15 namespace pmem
16 {
17 
18 namespace detail
19 {
20 
21 /*
22  * Base index type template.
23  */
24 template <typename T, T...>
25 struct integer_sequence {
26 };
27 
28 /*
29  * Size_t specialization of the integer sequence.
30  */
31 template <size_t... Indices>
32 using index_sequence = integer_sequence<size_t, Indices...>;
33 
34 template <typename T, T N, typename Enable, T... I>
35 struct make_integer_seq_impl;
36 
37 /*
38  * Helper for make_integer_sequence, specialization for N == 0 (end of
39  * recursion).
40  */
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...>;
45 };
46 
47 /*
48  * Helper for make_integer_sequence, base case.
49  */
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;
55 };
56 
57 /*
58  * Implementation of std::make_integer_sequence which works with C++11.
59  */
60 template <typename T, T N>
61 using make_integer_sequence = typename make_integer_seq_impl<T, N, void>::type;
62 
63 /*
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  *
72  * A helper alias template to convert any type parameter pack into an index
73  * sequence of the same length.
74  */
75 template <class... Types>
76 using index_sequence_for = make_index_sequence<sizeof...(Types)>;
77 
78 } /* namespace detail */
79 
80 } /* namespace pmem */
81 
82 #endif /* LIBPMEMOBJ_CPP_INTEGER_SEQUENCE_HPP */
Persistent memory namespace.
Definition: allocation_flag.hpp:15