1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_TYPE_ID_H_
6 #define BASE_TYPE_ID_H_
11 #include "base/base_export.h"
12 #include "base/compiler_specific.h"
13 #include "base/logging.h"
14 #include "base/strings/string_piece.h"
15 #include "build/build_config.h"
18 // Not ready for public consumption yet.
19 namespace experimental {
21 // A substitute for RTTI that uses the linker to uniquely reserve an address in
22 // the binary for each type.
25 bool constexpr operator==(const TypeId& other) const {
26 return type_id_ == other.type_id_;
29 bool constexpr operator!=(const TypeId& other) const {
30 return !(*this == other);
34 template <typename Type>
35 static constexpr TypeId Create() {
36 return TypeId(&TypeTag<Type>::dummy_var, PRETTY_FUNCTION);
39 std::string ToString() const;
42 template <typename Type>
44 constexpr static char dummy_var = 0;
47 constexpr TypeId(const void* type_id, const char* function_name)
50 function_name_(function_name),
56 const char* const function_name_;
58 const void* const type_id_;
61 template <typename Type>
62 constexpr char TypeId::TypeTag<Type>::dummy_var;
64 BASE_EXPORT std::ostream& operator<<(std::ostream& out, const TypeId& type_id);
66 } // namespace experimental
69 #endif // BASE_TYPE_ID_H_