[Beignet] [PATCH 1/7] add helper functions in ir::Constant and ir::ConstantSet

Xing, Homer homer.xing at intel.com
Fri Apr 26 18:35:00 PDT 2013


Thanks for telling me another way. Looks cool. But I am afraid your way does not work. Because you try to return a reference of a local variable.

If you don't believe, try that way by yourself, then you will see a compile error.

-----Original Message-----
From: Lu, Guanqun 
Sent: Saturday, April 27, 2013 9:21 AM
To: Xing, Homer; beignet at lists.freedesktop.org
Subject: RE: [Beignet] [PATCH 1/7] add helper functions in ir::Constant and ir::ConstantSet

> +    /*! Get a special constant */
> +    Constant& getConstant(const std::string & name) {
> +      size_t i = 0;
> +      for (auto c : constants) {
> +        if (c.getName() == name)
> +          return constants[i];
> +        i ++;
> +      }

> what the point of using 'i' here? I dont' think it's necessary.

Hi, see this: "return constants[i];"

[guanqun] then you can use 

for (auto &c : constants) {
  if (c.getName() == name)
     return c;

much simpler. :)  you really don't need an extra i in this block.



More information about the Beignet mailing list