Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > macro

Reply
Thread Tools

macro

 
 
Shao Miller
Guest
Posts: n/a
 
      01-20-2012
On 1/20/2012 10:50, Shao Miller wrote:
> Some restrictions apply:
> - There are only certain, specified, supported types for the 'M_OR'
> macro arguments.
> - If the 'M_OR' macro invocation is indeterminately sequenced relative
> to another 'M_OR' macro invocation, the behaviour is undefined.


I meant "unsequenced." Sorry about that.
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      01-20-2012
On 01/21/12 01:22 AM, Ben Bacarisse wrote:
> Ian Collins<ian-> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dedicated Macro or Normal Macro? John Ortt Digital Photography 5 11-22-2005 12:43 PM
Macro lens on a camera with a macro setting??? mitchell.chris@gmail.com Digital Photography 2 09-28-2005 07:55 AM
in S.E. Asia : Canon EOS 300d with 100 macro ED vs. Nikon D70 with Nikon 105 macro ? J. Cod Digital Photography 0 09-29-2004 05:46 AM
#define macro to enclose an older macro with strings Dead RAM C++ 20 07-14-2004 10:58 AM
macro name from macro? D Senthil Kumar C Programming 1 09-21-2003 07:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57