c++ - Macro including loop as an expression? -



c++ - Macro including loop as an expression? -

i utilize lot of macros implement mutual loop operations. example:

#define findidx(count, cond, out) out = count; (int = 0; < count; i++) \ if (cond) out= i;

used like:

int arr[5] = {1, 12, 13, 19, 21}; int idx; findidx(5, arr[i] == 13, idx); //idx set 2

is there clever way implement functionality expression, without sacrificing convenience, , without using c++11 (not available me)? assign result variable directly, or utilize result parameter function?

to embed statement in expression:

you can utilize gcc statement expression

you can utilize clang block

in c++03, can take static fellow member of anonymous struct in look (or @ to the lowest degree g++ doesn't complain):

foo( ((struct { static void f() { return; } }){}).f );

(so macro set loop code in body of f)

there no way in standard-compliant c, version (short of greenspunning). standard explicitly disallows using setjmp in comma-expressions, otherwise first thing you'd consider.

c++ c macros

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -