PMDK C++ bindings 1.13.0
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-2020, Intel Corporation */
3
9#ifndef LIBPMEMOBJ_CPP_INTEGER_SEQUENCE_HPP
10#define LIBPMEMOBJ_CPP_INTEGER_SEQUENCE_HPP
11
12#include <cstddef>
13
14namespace pmem
15{
16
17namespace detail
18{
19
20/*
21 * Base index type template.
22 */
23template <typename T, T...>
24struct integer_sequence {
25};
26
27/*
28 * Size_t specialization of the integer sequence.
29 */
30template <size_t... Indices>
31using index_sequence = integer_sequence<size_t, Indices...>;
32
33/*
34 * Empty base class.
35 *
36 * Subject of empty base optimization.
37 */
38template <typename T, T I, typename... Types>
39struct make_integer_seq_impl;
40
41/*
42 * Class ending recursive variadic template peeling.
43 */
44template <typename T, T I, T... Indices>
45struct make_integer_seq_impl<T, I, integer_sequence<T, Indices...>> {
46 typedef integer_sequence<T, Indices...> type;
47};
48
49/*
50 * Recursively create index while peeling off the types.
51 */
52template <typename N, N I, N... Indices, typename T, typename... Types>
53struct 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;
58};
59
60/*
61 * Make index sequence entry point.
62 */
63template <typename... Types>
64using make_index_sequence =
65 make_integer_seq_impl<size_t, 0, integer_sequence<size_t>, Types...>;
66
67/*
68 * 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.
70 */
71template <class... Types>
72using index_sequence_for = typename make_index_sequence<Types...>::type;
73
74} /* namespace detail */
75
76} /* namespace pmem */
77
78#endif /* LIBPMEMOBJ_CPP_INTEGER_SEQUENCE_HPP */
Persistent memory namespace.
Definition: allocation_flag.hpp:15