forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_class.h
More file actions
28 lines (21 loc) · 744 Bytes
/
custom_class.h
File metadata and controls
28 lines (21 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once
#include <typeindex>
#include <memory>
#include <c10/macros/Export.h>
#include <c10/macros/Macros.h>
#include <c10/util/Exception.h>
namespace c10 {
struct ClassType;
using ClassTypePtr = std::shared_ptr<ClassType>;
TORCH_API c10::ClassTypePtr getCustomClassTypeImpl(const std::type_index &tindex);
template <typename T>
const c10::ClassTypePtr& getCustomClassType() {
// Classes are never unregistered from getCustomClassTypeMap and the
// hash lookup can be a hot path, so just cache.
// For the same reason, it's fine If this ends up getting duplicated across
// DSO boundaries for whatever reason.
static c10::ClassTypePtr cache = getCustomClassTypeImpl(
std::type_index(typeid(T)));
return cache;
}
}