Monday, February 13, 2012

std::bind vs lambda

Compared with std::bind, lambda is not just more elegant, but also has better performance.
struct A
{
 void test() const { std::cout << "test" << std::endl; }
 ~A() { std::cout << "~A" << std::endl; }
 int i;
};

struct Test
{
 void test(A m) const { m.test(); }
};

void test(A m) { m.test(); }

int main() 
{
  Test t;
  {
    A m;
    std::bind(&Test::test, &t, m)();
  }
  {
    A m;
    [=](){t.test(m);}();
  }
  {
    A m;
    std::bind(&test, m)();
  }
  {
    A m;
    [=](){test(m);}();
  }
  return 0;
}
# gcc 4.6.2
test
~A
~A
~A
~A
~A
test
~A
~A
~A
test
~A
~A
~A
test
~A
~A
~A
# gcc 4.5.1
~A
test
~A
~A
~A
~A
~A
~A
test
~A
~A
~A
~A
test
~A
~A
~A
~A
test
~A
~A
~A

Thursday, February 9, 2012

My First Android App

To get a free playbook from RIM, I spent my spare time to write an android app. One month ago, I got my playbook. I have long time not to buy any new electronic product, so touch and big screen give me a lot of fun. When I am at home, I am happy to read source code online with github while lying on bed. However, I have no 3G, so I wonder how to read source code when I am out of door though I stay at home most of time. When I got the news of RIM Offers Free PlayBook to Attract Android Developers
,  I made my mind to write an offline source code view app with android. I have no android experience before, so I need a simple solution to compose the app with shortest time. The final solution is to combine OI file manager and Syntax Hiligher. The first version is delivered to blackberry app world. This is also my first time to use Eclipse to write a real app, which changes my previous bad impression to Eclipse totally. Current Eclipse is really much more usable than before.
Apk
Bar



Friday, February 3, 2012

做事必须搞清10个顺序

  1. 职场:先升值,再升职;
  2. 沟通:先求同,再求异;
  3. 执行:先完成,再完美;
  4. 学习:先记录,再记忆;
  5. 设计:先仿造,再创造;
  6. 创业:先成长,再成功;
  7. 发展:先站住,再站高;
  8. 人际:先交流,再交心;
  9. 先做好自己,再要求别人;
  10. 先解决心情,再解决事情。