@@ -336,45 +336,47 @@ static std::string AttrTypeToString(const proto::AttrType& type) {
336336    }
337337    default : {
338338      PADDLE_THROW (platform::errors::Fatal (
339-           " AttrType of type boost ::variant only supports specific data types." 
339+           " AttrType of type paddle ::variant only supports specific data types." 
340340          " However, detected unrecognized AttrType: %d" 
341341          type));
342342    }
343343  }
344344  return  ret;
345345}
346346
347- template  <typename  T>
348- static  std::string  GetAttrValue ( const  framework::Attribute& attr, 
349-                                  bool  is_vector ) {
347+ template  <typename  T,  bool  IsVector >
348+ static  typename   std::enable_if<IsVector, std::string>::type  GetAttrValue ( 
349+     const  framework::Attribute& attr ) {
350350  std::string val = " " 
351-   if  (is_vector) {
352-     val += " {" 
353-     for  (auto  x : BOOST_GET_CONST (std::vector<T>, attr)) {
354-       val += std::to_string (x) + " ," 
355-     }
356-     if  (val.size () > 1 ) val.pop_back ();
357-     val += " }" 
358-   } else  {
359-     val = std::to_string (BOOST_GET_CONST (T, attr));
351+   val += " {" 
352+   for  (auto  x : BOOST_GET_CONST (std::vector<T>, attr)) {
353+     val += std::to_string (x) + " ," 
360354  }
355+   if  (val.size () > 1 ) val.pop_back ();
356+   val += " }" 
361357  return  val;
362358}
363359
360+ template  <typename  T, bool  IsVector>
361+ static  typename  std::enable_if<!IsVector, std::string>::type GetAttrValue (
362+     const  framework::Attribute& attr) {
363+   return  std::to_string (BOOST_GET_CONST (T, attr));
364+ }
365+ 
364366static  std::pair<std::string, std::string> GetAttrType (
365367    const  framework::Attribute& attr, bool  is_arg) {
366368  std::string ret = " " 
367369  std::string val = " " 
368-   size_t  variant_pos = attr.which ();
370+   size_t  variant_pos = attr.index ();
369371  switch  (variant_pos) {
370372    case  (1 ): {
371373      ret = " int" 
372-       val = GetAttrValue<int >(attr , false );
374+       val = GetAttrValue<int , false >(attr );
373375      break ;
374376    }
375377    case  (2 ): {
376378      ret = " float" 
377-       val = GetAttrValue<float >(attr , false );
379+       val = GetAttrValue<float , false >(attr );
378380      break ;
379381    }
380382    case  (3 ): {
@@ -386,13 +388,13 @@ static std::pair<std::string, std::string> GetAttrType(
386388    case  (4 ): {
387389      ret = " std::vector<int>" 
388390      if  (is_arg) ret += " &" 
389-       val = GetAttrValue<int >(attr , true );
391+       val = GetAttrValue<int , true >(attr );
390392      break ;
391393    }
392394    case  (5 ): {
393395      ret = " std::vector<float>" 
394396      if  (is_arg) ret += " &" 
395-       val = GetAttrValue<float >(attr , true );
397+       val = GetAttrValue<float , true >(attr );
396398      break ;
397399    }
398400    case  (6 ): {
@@ -408,13 +410,13 @@ static std::pair<std::string, std::string> GetAttrType(
408410    }
409411    case  (7 ): {
410412      ret = " bool" 
411-       val = GetAttrValue<bool >(attr , false );
413+       val = GetAttrValue<bool , false >(attr );
412414      break ;
413415    }
414416    case  (8 ): {
415417      ret = " std::vector<bool>" 
416418      if  (is_arg) ret += " &" 
417-       val = GetAttrValue<bool >(attr , true );
419+       val = GetAttrValue<bool , true >(attr );
418420      break ;
419421    }
420422    case  (9 ): {
@@ -423,7 +425,7 @@ static std::pair<std::string, std::string> GetAttrType(
423425    }
424426    case  (10 ): {
425427      ret = " int64_t" 
426-       val = GetAttrValue<int64_t >(attr , false );
428+       val = GetAttrValue<int64_t , false >(attr );
427429      break ;
428430    }
429431    case  (11 ): {
@@ -434,18 +436,18 @@ static std::pair<std::string, std::string> GetAttrType(
434436    case  (12 ): {
435437      ret = " std::vector<int64_t>" 
436438      if  (is_arg) ret += " &" 
437-       val = GetAttrValue<int64_t >(attr , true );
439+       val = GetAttrValue<int64_t , true >(attr );
438440      break ;
439441    }
440442    case  (13 ): {
441443      ret = " std::vector<double>" 
442444      if  (is_arg) ret += " &" 
443-       val = GetAttrValue<double >(attr , true );
445+       val = GetAttrValue<double , true >(attr );
444446      break ;
445447    }
446448    default : {
447449      PADDLE_THROW (platform::errors::Fatal (
448-           " AttrType of type boost ::variant only supports specific data types." 
450+           " AttrType of type paddle ::variant only supports specific data types." 
449451          " However, detected unrecognized AttrType: %d" 
450452          variant_pos));
451453    }
0 commit comments