From 9f705a4bb937aade91126595a0fb0e4b994d9793 Mon Sep 17 00:00:00 2001 From: yuyang18 Date: Fri, 11 May 2018 13:20:41 +0800 Subject: [PATCH] Use int instead of VarType as unordered_map key --- paddle/fluid/framework/data_type.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/framework/data_type.cc b/paddle/fluid/framework/data_type.cc index f32258490..9e5f25589 100644 --- a/paddle/fluid/framework/data_type.cc +++ b/paddle/fluid/framework/data_type.cc @@ -19,8 +19,8 @@ namespace framework { struct DataTypeMap { std::unordered_map cpp_to_proto_; - std::unordered_map proto_to_cpp_; - std::unordered_map proto_to_str_; + std::unordered_map proto_to_cpp_; + std::unordered_map proto_to_str_; std::unordered_map cpp_to_size_; }; @@ -29,9 +29,10 @@ static DataTypeMap g_data_type_map_; template static inline void RegisterType(proto::VarType::Type proto_type, const std::string &name) { - g_data_type_map_.proto_to_cpp_.emplace(proto_type, typeid(T)); + g_data_type_map_.proto_to_cpp_.emplace(static_cast(proto_type), + typeid(T)); g_data_type_map_.cpp_to_proto_.emplace(typeid(T), proto_type); - g_data_type_map_.proto_to_str_.emplace(proto_type, name); + g_data_type_map_.proto_to_str_.emplace(static_cast(proto_type), name); g_data_type_map_.cpp_to_size_.emplace(typeid(T), sizeof(T)); } @@ -63,7 +64,7 @@ proto::VarType::Type ToDataType(std::type_index type) { std::type_index ToTypeIndex(proto::VarType::Type type) { std::call_once(register_once_flag_, RegisterAllTypes); - auto it = g_data_type_map_.proto_to_cpp_.find(type); + auto it = g_data_type_map_.proto_to_cpp_.find(static_cast(type)); if (it != g_data_type_map_.proto_to_cpp_.end()) { return it->second; } @@ -73,7 +74,7 @@ std::type_index ToTypeIndex(proto::VarType::Type type) { std::string DataTypeToString(const proto::VarType::Type type) { std::call_once(register_once_flag_, RegisterAllTypes); - auto it = g_data_type_map_.proto_to_str_.find(type); + auto it = g_data_type_map_.proto_to_str_.find(static_cast(type)); if (it != g_data_type_map_.proto_to_str_.end()) { return it->second; } -- GitLab