@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313limitations under the License. */
1414
1515#pragma once
16+ #include < string>
1617#include < typeindex>
1718#include " paddle/fluid/framework/framework.pb.h"
1819#include " paddle/fluid/platform/enforce.h"
@@ -22,26 +23,28 @@ namespace paddle {
2223namespace framework {
2324
2425inline proto::VarType::Type ToDataType (std::type_index type) {
25- using namespace paddle ::framework::proto;
2626 if (typeid (platform::float16).hash_code () == type.hash_code ()) {
2727 return proto::VarType::FP16;
28- } else if (typeid (float ).hash_code () == type.hash_code ()) {
28+ } else if (typeid (const float ).hash_code () == type.hash_code ()) {
29+ // CPPLint complains Using C-style cast. Use static_cast<float>() instead
30+ // One fix to this is to replace float with const float because
31+ // typeid(T) == typeid(const T)
32+ // http://en.cppreference.com/w/cpp/language/typeid
2933 return proto::VarType::FP32;
30- } else if (typeid (double ).hash_code () == type.hash_code ()) {
34+ } else if (typeid (const double ).hash_code () == type.hash_code ()) {
3135 return proto::VarType::FP64;
32- } else if (typeid (int ).hash_code () == type.hash_code ()) {
36+ } else if (typeid (const int ).hash_code () == type.hash_code ()) {
3337 return proto::VarType::INT32;
34- } else if (typeid (int64_t ).hash_code () == type.hash_code ()) {
38+ } else if (typeid (const int64_t ).hash_code () == type.hash_code ()) {
3539 return proto::VarType::INT64;
36- } else if (typeid (bool ).hash_code () == type.hash_code ()) {
40+ } else if (typeid (const bool ).hash_code () == type.hash_code ()) {
3741 return proto::VarType::BOOL;
3842 } else {
3943 PADDLE_THROW (" Not supported" );
4044 }
4145}
4246
4347inline std::type_index ToTypeIndex (proto::VarType::Type type) {
44- using namespace paddle ::framework::proto;
4548 switch (type) {
4649 case proto::VarType::FP16:
4750 return typeid (platform::float16);
@@ -62,7 +65,6 @@ inline std::type_index ToTypeIndex(proto::VarType::Type type) {
6265
6366template <typename Visitor>
6467inline void VisitDataType (proto::VarType::Type type, Visitor visitor) {
65- using namespace paddle ::framework::proto;
6668 switch (type) {
6769 case proto::VarType::FP16:
6870 visitor.template operator ()<platform::float16>();
@@ -88,7 +90,6 @@ inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
8890}
8991
9092inline std::string DataTypeToString (const proto::VarType::Type type) {
91- using namespace paddle ::framework::proto;
9293 switch (type) {
9394 case proto::VarType::FP16:
9495 return " float16" ;
0 commit comments