for_each function and operator()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George2

    for_each function and operator()

    Hello everyone,


    I can not find related information in MSDN, so I want to confirm here,
    that,

    the implementation of for_each is something like,

    Code:
    template <class A, class BB for_each (A begin, A end, B Func)
    {
    while (begin != end) Func(*begin++);
    return Func;
    }
    So, operator(*A) of class Func will be invoked? Right?


    thanks in advance,
    George
  • Rolf Magnus

    #2
    Re: for_each function and operator()

    George2 wrote:
    Hello everyone,
    >
    >
    I can not find related information in MSDN, so I want to confirm here,
    that,
    >
    the implementation of for_each is something like,
    >
    Code:
    template <class A, class BB for_each (A begin, A end, B Func)
    {
        while (begin != end) Func(*begin++);
        return Func;
    }
    >
    So, operator(*A) of class Func will be invoked? Right?
    Yes.


    Comment

    • Victor Bazarov

      #3
      Re: for_each function and operator()

      George2 wrote:
      I can not find related information in MSDN, so I want to confirm here,
      that,
      >
      the implementation of for_each is something like,
      >
      Code:
      template <class A, class BB for_each (A begin, A end, B Func)
      {
         while (begin != end) Func(*begin++);
         return Func;
      }
      >
      So, operator(*A) of class Func will be invoked? Right?
      If 'B' is a class, then yes, operator(). If 'B' is a function type,
      then the function 'Func' will be called.

      V
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask


      Comment

      • terminator

        #4
        Re: for_each function and operator()

        On Dec 3, 4:30 pm, George2 <george4acade.. .@yahoo.comwrot e:
        Hello everyone,
        >
        I can not find related information in MSDN, so I want to confirm here,
        that,
        if your tools are not outdated you can just right click on what you
        have typed and select 'go to definition'.
        >
        the implementation of for_each is something like,
        >
        Code:
        template <class A, class BB for_each (A begin, A end, B Func)
        {
            while (begin != end) Func(*begin++);
            return Func;}
        >
        >
        MS actualy devices a for loop instead of while and uses preincrement(+
        +it) operation which results in more optimized and readable
        implementation.


        regards,
        FM.

        Comment

        Working...