Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
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::make_index_sequence;
33  using std::index_sequence_for;
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 size() noexcept { return sizeof...(Ints); }
41  };
42 
43  // --------------------------------------------------------------
44  namespace internal
45  {
46  template <class Sequence1, class Sequence2>
47  struct merge_and_renumber;
48 
49  template <size_t... I1, size_t... I2>
50  struct merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>>
51  : index_sequence<I1..., (sizeof...(I1)+I2)...>
52  { };
53  }
54  // --------------------------------------------------------------
55 
56  template <size_t N>
57  struct make_index_sequence
58  : internal::merge_and_renumber<typename make_index_sequence<N/2>::type,
59  typename make_index_sequence<N - N/2>::type>
60  {};
61 
62  template<> struct make_index_sequence<0> : index_sequence<> { };
63  template<> struct make_index_sequence<1> : index_sequence<0> { };
64 
65  template<class... T>
66  using index_sequence_for = make_index_sequence<sizeof...(T)>;
67 #endif
68 }
69 DEAL_II_NAMESPACE_CLOSE
70 
71 #endif // dealii_cxx14_memory_h