• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NVRAM_MESSAGES_TYPE_TRAITS_H_
18 #define NVRAM_MESSAGES_TYPE_TRAITS_H_
19 
20 extern "C" {
21 #include <stddef.h>
22 }
23 
24 // A subset of utilities similar to what is available in <type_traits>. We have
25 // our own standalone version here since not all target platforms have a full
26 // C++ standard library.
27 
28 namespace nvram {
29 
30 template <typename T>
31 struct remove_const {
32   using Type = T;
33 };
34 template <typename T>
35 struct remove_const<const T> {
36   using Type = T;
37 };
38 
39 template <typename T>
40 struct remove_reference {
41   using Type = T;
42 };
43 template <typename T>
44 struct remove_reference<T&> {
45   using Type = T;
46 };
47 template <typename T>
48 struct remove_reference<T&&> {
49   using Type = T;
50 };
51 
52 template <bool value, typename T = void>
53 struct enable_if {};
54 
55 template <typename T>
56 struct enable_if<true, T> {
57   using Type = T;
58 };
59 
60 template <typename T, T const_value>
61 struct integral_constant {
62   static constexpr T value = const_value;
63 };
64 
65 using true_type = integral_constant<bool, true>;
66 using false_type = integral_constant<bool, false>;
67 
68 template <typename T>
69 T declval();
70 
71 template <size_t... index>
72 struct index_sequence {};
73 
74 template <size_t size, size_t... indices>
75 struct make_index_sequence_builder {
76   using Type = typename make_index_sequence_builder<size - 1,
77                                                     size - 1,
78                                                     indices...>::Type;
79 };
80 
81 template <size_t... indices>
82 struct make_index_sequence_builder<0, indices...> {
83   using Type = index_sequence<indices...>;
84 };
85 
86 template <size_t size>
87 constexpr typename make_index_sequence_builder<size>::Type
88 make_index_sequence(){
89   return typename make_index_sequence_builder<size>::Type();
90 };
91 
92 }  // namespace nvram
93 
94 #endif  // NVRAM_MESSAGES_TYPE_TRAITS_H_
95