xref: /aosp_15_r20/external/cronet/base/types/is_instantiation.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TYPES_IS_INSTANTIATION_H_
6 #define BASE_TYPES_IS_INSTANTIATION_H_
7 
8 #include <type_traits>
9 
10 namespace base {
11 namespace internal {
12 
13 // True if and only if `T` is `C<Types...>` for some set of types, i.e. `T` is
14 // an instantiation of the template `C`.
15 //
16 // This is false by default. We specialize it to true below for pairs of
17 // arguments that satisfy the condition.
18 template <template <typename...> class C, typename T>
19 inline constexpr bool is_instantiation_v = false;
20 
21 template <template <typename...> class C, typename... Ts>
22 inline constexpr bool is_instantiation_v<C, C<Ts...>> = true;
23 
24 }  // namespace internal
25 
26 // True if and only if the type `T` is an instantiation of the template `C` with
27 // some set of type arguments.
28 //
29 // Note that there is no allowance for reference or const/volatile qualifiers;
30 // if these are a concern you probably want to feed through `std::decay_t<T>`.
31 template <template <typename...> class C, typename T>
32 concept is_instantiation = internal::is_instantiation_v<C, T>;
33 
34 }  // namespace base
35 
36 #endif  // BASE_TYPES_IS_INSTANTIATION_H_
37