Reference documentation for deal.II version 9.1.0-pre
utility.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 #ifndef dealii_cxx14_utility_h
16 #define dealii_cxx14_utility_h
17 
18 #include <deal.II/base/config.h>
19 
20 #include <utility>
21 
22 #ifndef DEAL_II_WITH_CXX14
23 // needed for array type check
24 # include <type_traits>
25 #endif
26 
27 DEAL_II_NAMESPACE_OPEN
28 namespace std_cxx14
29 {
30 #ifdef DEAL_II_WITH_CXX14
31  using std::index_sequence;
32  using std::index_sequence_for;
33  using std::make_index_sequence;
34 #else
35  template <size_t... Ints>
36  struct index_sequence
37  {
38  using type = index_sequence;
39  using value_type = size_t;
40  static constexpr std::size_t
41  size() noexcept
42  {
43  return sizeof...(Ints);
44  }
45  };
46 
47  // --------------------------------------------------------------
48  namespace internal
49  {
50  template <class Sequence1, class Sequence2>
51  struct merge_and_renumber;
52 
53  template <size_t... I1, size_t... I2>
54  struct merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>>
55  : index_sequence<I1..., (sizeof...(I1) + I2)...>
56  {};
57  } // namespace internal
58  // --------------------------------------------------------------
59 
60  template <size_t N>
61  struct make_index_sequence : internal::merge_and_renumber<
62  typename make_index_sequence<N / 2>::type,
63  typename make_index_sequence<N - N / 2>::type>
64  {};
65 
66  template <>
67  struct make_index_sequence<0> : index_sequence<>
68  {};
69  template <>
70  struct make_index_sequence<1> : index_sequence<0>
71  {};
72 
73  template <class... T>
74  using index_sequence_for = make_index_sequence<sizeof...(T)>;
75 #endif
76 } // namespace std_cxx14
77 DEAL_II_NAMESPACE_CLOSE
78 
79 #endif // dealii_cxx14_memory_h