Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #74710

Re: CAlive to introduce flowofs

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: CAlive to introduce flowofs
Date 2015-11-03 11:20 +1300
Message-ID <d9q5tpF7v31U7@mid.individual.net> (permalink)
References (1 earlier) <n18j7u$g97$1@dont-email.me> <d9q1v9F7v31U3@mid.individual.net> <n18jjk$heh$1@dont-email.me> <d9q30lF7v31U5@mid.individual.net> <n18ljs$qqt$1@dont-email.me>

Show all headers | View raw


Bartc wrote:
> On 02/11/2015 21:31, Ian Collins wrote:
>> Bartc wrote:
>>> On 02/11/2015 21:13, Ian Collins wrote:
>>>> Bartc wrote:
>
>>>>> This is one of your ideas that I like, and have implemented my own
>>>>> version.
>>>>
>>>> It is also one which (as discussed last year) already available in
>>>> C++ :)
>>>
>>> I don't remember the C++ version. What's the feature called there?
>>
>> A function object (functor).
>
> OK. My initial reading suggests that the concept is rather more
> elaborate and general purpose than what is being discussed here, which
> is a way of getting from X in a function to Y in the same function, then
> returning to just after X. I believe that what I've implemented is very
> easy to understand.
>
> (I've looked at the link to last year's thread, I couldn't see any
> examples of functors there. What would my version of Rick's example look
> like using functors? (The fact that I have to ask doesn't bode well!). A
> link to one of last year's posts will do.)

One form would be:

struct my_function
{
   int result;
   int count;
   int value;

   void five_count()
   {
     result = 5*value;
   }

   void ten_count()
   {
     result = 10*value;
   }

   void greater_than_ten_count()
   {
     result = 42*value;
   }

   int operator()( int c, int v )
   {
     count = c;
     value = v;

     if (count < 5)         five_count();
     else if (count < 10)   ten_count();
     else                   greater_than_ten_count();

     return result;
   }
};

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 11:20 -0800
  Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 11:27 -0800
    Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 11:34 -0800
  Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 11:57 -0800
  Re: CAlive to introduce flowofs supercat@casperkitty.com - 2015-11-02 12:18 -0800
    Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 12:24 -0800
      Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 12:48 -0800
    Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 12:40 -0800
  Re: CAlive to introduce flowofs Bartc <bc@freeuk.com> - 2015-11-02 21:08 +0000
    Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 10:13 +1300
      Re: CAlive to introduce flowofs Bartc <bc@freeuk.com> - 2015-11-02 21:14 +0000
        Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 10:31 +1300
          Re: CAlive to introduce flowofs Bartc <bc@freeuk.com> - 2015-11-02 21:48 +0000
            Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 11:20 +1300
              Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 14:33 -0800
                Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 15:03 -0800
                Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 12:05 +1300
                Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 15:08 -0800
                Re: CAlive to introduce flowofs supercat@casperkitty.com - 2015-11-02 16:44 -0800
                Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 17:20 -0800
                Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 17:06 +1300
                Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 20:13 -0800
              Re: CAlive to introduce flowofs Bartc <bc@freeuk.com> - 2015-11-03 12:43 +0000
                Re: CAlive to introduce flowofs David Brown <david.brown@hesbynett.no> - 2015-11-03 14:20 +0100
                Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-04 08:57 +1300
      Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 14:31 -0800

csiph-web