• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 The Abseil Authors.
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 //      https://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 ABSL_BASE_INTERNAL_FAST_TYPE_ID_H_
18 #define ABSL_BASE_INTERNAL_FAST_TYPE_ID_H_
19 
20 #include "absl/base/config.h"
21 
22 namespace absl {
23 ABSL_NAMESPACE_BEGIN
24 namespace base_internal {
25 
26 template <typename Type>
27 struct FastTypeTag {
28   constexpr static char dummy_var = 0;
29 };
30 
31 template <typename Type>
32 constexpr char FastTypeTag<Type>::dummy_var;
33 
34 // FastTypeId<Type>() evaluates at compile/link-time to a unique pointer for the
35 // passed-in type. These are meant to be good match for keys into maps or
36 // straight up comparisons.
37 using FastTypeIdType = const void*;
38 
39 template <typename Type>
FastTypeId()40 constexpr inline FastTypeIdType FastTypeId() {
41   return &FastTypeTag<Type>::dummy_var;
42 }
43 
44 }  // namespace base_internal
45 ABSL_NAMESPACE_END
46 }  // namespace absl
47 
48 #endif  // ABSL_BASE_INTERNAL_FAST_TYPE_ID_H_
49