zoukankan      html  css  js  c++  java
  • Review: functor / function object

    Function object, also called functor, functional, or functionoid,is a computer programming construct allowing an object to be invoked or called as though it were an ordinary function, usually with the same syntax.

    Several notes for it:

    1. In C, there is only function pointer; in C#, there is only delegate; while in C++, by overriding operator() of a class/struct, its instance can be used just like a function pointer:

     functor_class Y;
    int result = Y( a, b );
    2. Its advantages:
      1) performance. Due to it's actually called like Y(a, b) so the function can be known at compile time, so can be set inlined, which will improve performance.
    2) can maintain state. It's actually a object passed into a container like std::map for comparison for sorting, so it can have its state. It can't be achieved by function pointer
    or delegate.

     

  • 相关阅读:
    6月17日
    6月16日
    6月15日
    6月14日
    6月13日
    6月12日
    6月11日
    6月10日
    6月8日
    6月5日
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1914075.html
Copyright © 2011-2022 走看看