• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 INCLUDE_PERFETTO_BASE_TEMPLATE_UTIL_H_
18 #define INCLUDE_PERFETTO_BASE_TEMPLATE_UTIL_H_
19 
20 #include <cstddef>
21 #include <type_traits>
22 
23 namespace perfetto {
24 namespace base {
25 
26 // Helper to express preferences in an overload set. If more than one overload
27 // is available for a given set of parameters the overload with the higher
28 // priority will be chosen.
29 template <size_t I>
30 struct priority_tag : priority_tag<I - 1> {};
31 
32 template <>
33 struct priority_tag<0> {};
34 
35 // enable_if_t is an implementation of std::enable_if_t from C++14.
36 //
37 // Specification:
38 // https://en.cppreference.com/w/cpp/types/enable_if
39 template <bool B, class T = void>
40 using enable_if_t = typename std::enable_if<B, T>::type;
41 
42 // decay_t is an implementation of std::decay_t from C++14.
43 //
44 // Specification:
45 // https://en.cppreference.com/w/cpp/types/decay
46 template <class T>
47 using decay_t = typename std::decay<T>::type;
48 
49 // remove_cvref is an implementation of std::remove_cvref from
50 // C++20.
51 //
52 // Specification:
53 // https://en.cppreference.com/w/cpp/types/remove_cvref
54 
55 template <class T>
56 struct remove_cvref {
57   using type = typename std::remove_cv<typename std::remove_cv<
58       typename std::remove_reference<T>::type>::type>::type;
59 };
60 template <class T>
61 using remove_cvref_t = typename remove_cvref<T>::type;
62 
63 // Check if a given type is a specialization of a given template:
64 // is_specialization<T, std::vector>::value.
65 
66 template <typename Type, template <typename...> class Template>
67 struct is_specialization : std::false_type {};
68 
69 template <template <typename...> class Ref, typename... Args>
70 struct is_specialization<Ref<Args...>, Ref> : std::true_type {};
71 
72 }  // namespace base
73 }  // namespace perfetto
74 
75 #endif  // INCLUDE_PERFETTO_BASE_TEMPLATE_UTIL_H_
76