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


Groups > comp.lang.c > #15981

Re: [OT] Re: macro

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: [OT] Re: macro
Date 2012-01-21 07:58 +1300
Message-ID <9ntrq3F524U8@mid.individual.net> (permalink)
References (10 earlier) <9nnjboFaaoU3@mid.individual.net> <20120118130142.908@kylheku.com> <9ns0koF524U3@mid.individual.net> <9ns3j4F524U4@mid.individual.net> <0.840318e8171f503ababc.20120120122206GMT.878vl2lg29.fsf@bsb.me.uk>

Show all headers | View raw


On 01/21/12 01:22 AM, Ben Bacarisse wrote:
> Ian Collins<ian-news@hotmail.com>  writes:
>>> On 01/19/12 10:09 AM, Kaz Kylheku wrote:
>>>>
>>>> Here is a requirement:
>>>>
>>>>      or(x, y)
>>>>
>>>> This must evaluate X.  If X is nonzero, then the value X is the
>>>> result, and Y is not evaluated. Otherwise the result is the value of
>>>> Y.  X is evaluated exactly once, and Y at most once.
> <snip>
>> I couldn't resist following this up, so here's a rather OT C++0x solution:
>>
>> template<typename X, typename Y, typename... Args>
>> auto do_or( X x, Y y, Args... args ) ->  decltype(x+y( args...))
>> {
>>    if( x ) return x;
>>
>>    return y( args...);
>> }
>
> This may be a close as one can get (I can't get any closer!) but it
> doesn't strike me as being "a solution" because of the need to wrap the
> original expression, y, in a function to delay its execution.  C++11's
> lambdas make this simple enough, but it still won't look as readable as
> the original:
>
>      do_or(a++, [&b]{return b++;})
> vs
>      or(a++, b++)
>
> That may, however, be an advantage, since having odd evaluation semantics
> for the arguments of something that looks like a function is asking for
> trouble.  (Yes, I know it was posed as an academic exercise so this is
> an incidental point).
>
> BTW, what's the purpose of the extra args?  I'd have though that the
> availability of lambdas renders these unnecessary.  If it's to allow a
> non-lambda function as a wrapper for the expression, then would you not
> need to write Args&... args to allow for modification?

I overlooked the lambdas.

-- 
Ian Collins

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


Thread

macro dspfun <dspfun@hotmail.com> - 2012-01-15 05:29 -0800
  Re: macro Dr Nick <3-nospam@temporary-address.org.uk> - 2012-01-15 13:44 +0000
    Re: macro dspfun <dspfun@hotmail.com> - 2012-01-15 05:58 -0800
      Re: macro "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> - 2012-01-15 15:34 +0100
      Re: macro "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-01-15 06:37 -0800
        Re: macro dspfun <dspfun@hotmail.com> - 2012-01-15 07:28 -0800
          Re: macro Philip Lantz <prl@canterey.us> - 2012-01-15 17:30 -0800
            Re: macro Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-16 00:18 -0800
              Re: macro Hans Vlems <hvlems@freenet.de> - 2012-01-16 00:52 -0800
                Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-16 22:08 +1300
                Re: macro Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-16 03:04 -0800
                Re: macro Markus Wichmann <nullplan@gmx.net> - 2012-01-16 12:42 +0100
        Re: macro jgk@panix.com (Joe keane) - 2012-01-16 14:48 +0000
          Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-16 12:01 -0800
            Re: macro Philip Lantz <prl@canterey.us> - 2012-01-17 01:02 -0800
              Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-17 13:05 -0800
                Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-18 13:12 +1300
                Re: macro dspfun <dspfun@hotmail.com> - 2012-01-18 01:05 -0800
                Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-18 22:57 +1300
                Re: macro "osmium" <r124c4u102@comcast.net> - 2012-01-18 06:22 -0600
                Re: macro dspfun <dspfun@hotmail.com> - 2012-01-18 07:50 -0800
                Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 14:09 +1300
                Re: macro blp@cs.stanford.edu (Ben Pfaff) - 2012-01-18 11:28 -0800
                Re: macro Kaz Kylheku <kaz@kylheku.com> - 2012-01-18 21:09 +0000
                Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 15:08 +1300
                [OT] Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 15:58 +1300
                Re: [OT] Re: macro Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-20 12:22 +0000
                Re: [OT] Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-21 07:58 +1300
                Re: macro James Kuyper <jameskuyper@verizon.net> - 2012-01-19 22:47 -0500
                Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 17:06 +1300
                Re: macro James Kuyper <jameskuyper@verizon.net> - 2012-01-20 00:12 -0500
                Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-20 18:28 +1300
                Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-20 03:21 -0800
                Re: macro Shao Miller <sha0.miller@gmail.com> - 2012-01-20 10:50 -0500
                Re: macro Shao Miller <sha0.miller@gmail.com> - 2012-01-20 11:46 -0500
                Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-18 14:24 -0800
                Re: macro jgk@panix.com (Joe keane) - 2012-01-18 22:36 +0000
                Re: macro Kaz Kylheku <kaz@kylheku.com> - 2012-01-18 22:50 +0000
            Re: macro jgk@panix.com (Joe keane) - 2012-01-17 22:08 +0000
  Re: macro Keith Thompson <kst-u@mib.org> - 2012-01-15 08:00 -0800
  Re: macro NEON China BLUE <chine.bleu@yahoo.com> - 2012-01-15 08:15 -0800
  Re: macro Ian Collins <ian-news@hotmail.com> - 2012-01-16 09:04 +1300
    Re: macro Philip Lantz <prl@canterey.us> - 2012-01-15 17:36 -0800
  Re: macro Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-16 12:01 +0000

csiph-web