Skip to content

Commit 9f705a4

Browse files
committed
Use int instead of VarType as unordered_map key
1 parent c4d6daa commit 9f705a4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

paddle/fluid/framework/data_type.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ namespace framework {
1919

2020
struct DataTypeMap {
2121
std::unordered_map<std::type_index, proto::VarType::Type> cpp_to_proto_;
22-
std::unordered_map<proto::VarType::Type, std::type_index> proto_to_cpp_;
23-
std::unordered_map<proto::VarType::Type, std::string> proto_to_str_;
22+
std::unordered_map<int, std::type_index> proto_to_cpp_;
23+
std::unordered_map<int, std::string> proto_to_str_;
2424
std::unordered_map<std::type_index, size_t> cpp_to_size_;
2525
};
2626

@@ -29,9 +29,10 @@ static DataTypeMap g_data_type_map_;
2929
template <typename T>
3030
static inline void RegisterType(proto::VarType::Type proto_type,
3131
const std::string &name) {
32-
g_data_type_map_.proto_to_cpp_.emplace(proto_type, typeid(T));
32+
g_data_type_map_.proto_to_cpp_.emplace(static_cast<int>(proto_type),
33+
typeid(T));
3334
g_data_type_map_.cpp_to_proto_.emplace(typeid(T), proto_type);
34-
g_data_type_map_.proto_to_str_.emplace(proto_type, name);
35+
g_data_type_map_.proto_to_str_.emplace(static_cast<int>(proto_type), name);
3536
g_data_type_map_.cpp_to_size_.emplace(typeid(T), sizeof(T));
3637
}
3738

@@ -63,7 +64,7 @@ proto::VarType::Type ToDataType(std::type_index type) {
6364

6465
std::type_index ToTypeIndex(proto::VarType::Type type) {
6566
std::call_once(register_once_flag_, RegisterAllTypes);
66-
auto it = g_data_type_map_.proto_to_cpp_.find(type);
67+
auto it = g_data_type_map_.proto_to_cpp_.find(static_cast<int>(type));
6768
if (it != g_data_type_map_.proto_to_cpp_.end()) {
6869
return it->second;
6970
}
@@ -73,7 +74,7 @@ std::type_index ToTypeIndex(proto::VarType::Type type) {
7374

7475
std::string DataTypeToString(const proto::VarType::Type type) {
7576
std::call_once(register_once_flag_, RegisterAllTypes);
76-
auto it = g_data_type_map_.proto_to_str_.find(type);
77+
auto it = g_data_type_map_.proto_to_str_.find(static_cast<int>(type));
7778
if (it != g_data_type_map_.proto_to_str_.end()) {
7879
return it->second;
7980
}

0 commit comments

Comments
 (0)